Angular material select dropdown with mat select trigger.
Trying to create select dropdown like this :
https://stackblitz.com/angular/omvmgjjbnnq?file=app%2Fselect-custom-trigger-example.ts
My Code :
component.ts
export class SelectCustomTriggerExample implements OnInit {
dispForm : FormGroup
constructor(private fb : FormBuilder) {}
ngOnInit() {
this.dispForm = this.fb.group({
toppings : ['']
})
}
toppingList: string[] = ['Extra cheese', 'Mushroom', 'Onion', 'Pepperoni', 'Sausage', 'Tomato'];
}
component.html
<mat-form-field>
<form [formGroup]="dispForm">
<mat-select placeholder="Toppings" formControlName="toppings" multiple>
<mat-select-trigger>
{{toppings.value ? toppings.value[0] : ''}}
<span *ngIf="toppings.value?.length > 1" class="example-additional-selection">
(+{{toppings.value.length - 1}} {{toppings.value?.length === 2 ? 'other' : 'others'}})
</span>
</mat-select-trigger>
<mat-option *ngFor="let topping of toppingList" [value]="topping">{{topping}}</mat-option>
</mat-select>
</form>
</mat-form-field>
I have changed formControl to formControlName and code stopped working