我在 Angular 中使用属性绑定来取消选择所有复选框,但它没有按预期工作。我的预期:当我单击“清除”按钮选择一个或多个复选框后,它应该取消选择所有复选框。这是我的笨蛋
isSelected is the boolean variable which i have used to set the 'checked' attribute of checkbox.
模板:
<div *ngFor="let item of items">
<input [checked]="isSelected" type="checkbox">{{item}}
</div>
<button (click)="onClear()">Clear All</button>
零件
private items = ['a', 'b', 'c', 'd'];
private isSelected = false;
constructor() {
}
onClear(){
this.isSelected = false;
}