请查看以下示例代码,其中演示了如何在Angular 10中使用Angular Material复选框数组,并且如何传递复选框的值:
import { MatCheckboxModule } from '@angular/material/checkbox';
@NgModule({
imports: [
MatCheckboxModule
],
// ...
})
export class AppModule { }
{{item.label}}
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-checkbox-example',
templateUrl: './checkbox-example.component.html',
styleUrls: ['./checkbox-example.component.css']
})
export class CheckboxExampleComponent implements OnInit {
checkboxArray = [
{ label: 'Option 1', checked: false },
{ label: 'Option 2', checked: false },
{ label: 'Option 3', checked: false }
];
constructor() { }
ngOnInit() {
}
handleCheckboxChange() {
// 处理复选框值的变化
console.log(this.checkboxArray);
}
}
这样,当复选框的值发生变化时,handleCheckboxChange方法将会被调用,并且可以通过this.checkboxArray来获取复选框的值。