This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| // Electronics | |
| { | |
| id: '1', | |
| name: 'Wireless Noise-Cancelling Headphones', | |
| description: | |
| 'Premium wireless headphones with active noise cancellation and 30-hour battery life', | |
| price: 299.99, | |
| imageUrl: | |
| 'https://images.unsplash.com/photo-1505740420928-5e560c06d30e?auto=format&w=400&q=80', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Include theming for Angular Material with `mat.theme()`. | |
| // This Sass mixin will define CSS variables that are used for styling Angular Material | |
| // components according to the Material 3 design spec. | |
| // Learn more about theming and how to use it for your application's | |
| // custom components at https://material.angular.dev/guide/theming | |
| @use '@angular/material' as mat; | |
| @use 'tailwindcss'; | |
| html { | |
| @include mat.theme( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @NgModule({ | |
| declarations: [AppComponent], | |
| imports: [ | |
| BrowserModule | |
| ], | |
| providers: [ | |
| { | |
| provide: HTTP_INTERCEPTORS, | |
| useClass: NetworkInterceptor, | |
| multi: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="content"> | |
| <app-chips-multi-select [options]="options" [formControl]="chipsControl"> | |
| </app-chips-multi-select> | |
| <mat-divider></mat-divider> | |
| <h3>Value: {{chipsControlValue$ | async}}</h3> | |
| <mat-divider></mat-divider> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component({ | |
| selector: 'app-chips-multi-select', | |
| templateUrl: './chips-multi-select.component.html', | |
| styleUrls: ['./chips-multi-select.component.scss'], | |
| providers: [ | |
| { | |
| provide: NG_VALUE_ACCESSOR, | |
| useExisting: ChipsMultiSelectComponent, | |
| multi: true, | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| disabled = false; | |
| setDisabledState?(isDisabled: boolean): void { | |
| this.disabled = isDisabled; | |
| } | |
| toggleSelection(chip: MatChip) { | |
| if (!this.disabled) chip.toggleSelected(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ngAfterViewInit() { | |
| this.chipList.chipSelectionChanges | |
| .pipe( | |
| untilDestroyed(this), | |
| map((event) => event.source)) | |
| .subscribe((chip) => { | |
| if (chip.selected) { | |
| this.value = [...this.value, chip.value]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @ViewChild(MatChipList) chipList!: MatChipList; | |
| value: string[] = []; | |
| writeValue(value: string[]): void { | |
| // When form value set when chips list initialized | |
| if (this.chipList && value) { | |
| this.selectChips(value); | |
| } else if (value) { | |
| // When chips not initialized |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| onChange!: (value: string[]) => void; | |
| registerOnChange(fn: any): void { | |
| this.onChange = fn; | |
| } | |
| propagateChange(value: string[]) { | |
| if (this.onChange) { | |
| this.onChange(value); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class ChipsMultiSelectComponent implements OnInit, ControlValueAccessor { | |
| writeValue(value: string[]): void { | |
| } | |
| registerOnChange(fn: any): void { | |
| } | |
| registerOnTouched(fn: any): void { | |
| } |
NewerOlder