所有我正在使用角材进行多选下拉菜单,我能够得到
选定的值,任何一项都可以帮助获取多选下拉菜单的未经检查的值
答案 0 :(得分:0)
您可以通过以下方式进行检查,
在 component.html
中<mat-form-field>
<mat-select placeholder="Toppings" (selectionChange)="onChange($event.value)" multiple>
<mat-option *ngFor="let topping of toppingList" [value]="topping">{{topping}}</mat-option>
</mat-select>
</mat-form-field>
和 component.ts
中toppingList: string[] = ['Extra cheese', 'Mushroom', 'Onion', 'Pepperoni', 'Sausage', 'Tomato'];
selectedList: any = []; // store selected options here
onChange(event) {
let missing = null;
for (let i = 0; i < this.selectedList.length; i++) {
if (event.indexOf(this.selectedList[i]) == -1) missing = this.selectedList[i]; // Current[i] isn't in prev
}
if (missing)
alert(missing);
this.selectedList = event;
}
这是Stackblitz演示