【发布时间】:2021-09-16 01:53:29
【问题描述】:
当我尝试将 $event.target.checked 与 angular mat-checkbox 一起使用时,它会给出一个错误,指出 -“无法读取 Object.eval [as handleEvent] 处未定义的属性 'checked'” 这是为 Angular8 上的复选框传递多个值
onChange(cls: string, isChecked: boolean) {
const clsFormArray = < FormArray > this.myForm.controls.usercls;
if (isChecked) {
clsFormArray.push(new FormControl(cls));
} else {
let index = clsFormArray.controls.findIndex(x => x.value == cls);
clsFormArray.removeAt(index);
}
}
<mat-checkbox class="example-margin" (change)="onChange(data.cls, $event.target.checked)">
{{ data.cls }}
</mat-checkbox>
<mat-checkbox class="example-margin"(change)="onChange(data.cls,$event.target.checked)">
{{ data.cls }}
</mat-checkbox>
onChange(cls: string, isChecked: boolean) {
const clsFormArray = <FormArray>this.myForm.controls.usercls;
if (isChecked) {
clsFormArray.push(new FormControl(cls));
} else {
let index = clsFormArray.controls.findIndex(x => x.value == cls);
clsFormArray.removeAt(index);
}
}
我期望类被推送并添加到数组中,所以 我可以打印出来
【问题讨论】:
标签: angular typescript angular-material