【发布时间】:2021-01-29 19:05:46
【问题描述】:
我正在使用角度。我有一个多重选择(垫选择),我想在数组中发送选定的值我尝试使用 selectionchange 并获取值并将其推送到数组中,但之后如果我取消选择从数组中弹出的选项而不是一个值添加到我的数组中。我想如果我取消选择任何元素,则该数组中没有插入新元素
提前致谢
<mat-form-field>
<mat-select (selectionChange)="change($event)" multiple >
<mat-option *ngFor="let i of user" [value]="i">
{{ i.name }}
</mat-option>
</mat-select>
</mat-form-field>
change(event) {
console.log(event);
this.e=event.value
console.log('ttttt',this.e)
for(var i=0;i<this.e.length;i++)
{
var local=this.e[i].value;
}
this.arr.push(local);
console.log('arr',this.arr)
}
【问题讨论】:
标签: javascript arrays angular