【发布时间】:2019-09-06 14:36:36
【问题描述】:
我正在使用来自 Angular Material 的多重选择。我能够获取项目的值和检查值(真/假)。我需要创建一个数组,如果该项为真则推送,如果该项为假则弹出。
我已经尝试获取布尔值:
html:
<mat-form-field>
<mat-select multiple placeholder="Select Shows">
<mat-option (onSelectionChange)="change($event)" *ngFor="let food of foods" [value]="food.value">
{{ food.viewValue }}
</mat-option>
</mat-select>
</mat-form-field>
.ts:
change(event)
{
if(event.isUserInput) {
console.log(event.source.value, event.source.selected);
this.ShowArray.push(event.source.value)
}
}
预期输出:
["value1","value2","value3"]; //Inserted at first
["value1","value3"]; //Since the value2 is checked again, so it becomes false.
【问题讨论】:
-
event.source.selected是布尔值吗? -
是的。它是布尔值