<mat-form-field>
<mat-label>Toppings</mat-label>
<mat-select [formControl]="toppings" multiple>
// The following Sample text or any dynamic value will not be displayed on the
// initial run. It only shows the value if an option is selected from the
// dropdown
<mat-select-trigger> Sample text </mat-select-trigger>
@for (topping of toppingList; track topping) {
<mat-option [value]="topping">{{topping}}</mat-option>
}
</mat-select>
</mat-form-field>
stackblitz链接:
<mat-form-field>
<mat-label>Toppings</mat-label>
<mat-select [formControl]="toppings" multiple>
<mat-select-trigger>
<div class="chips">
@for (topping of toppings.value; track $index) {
<mat-chip (removed)="removeTopping(topping)">
{{ topping }}
<button matChipRemove>
<mat-icon>cancel</mat-icon>
</button>
</mat-chip>
}
</div>
</mat-select-trigger>
@for (topping of toppingList; track topping) {
<mat-option [value]="topping">{{topping}}</mat-option>
}
</mat-select>
</mat-form-field>