<md-checkbox [align]="end" *ngFor="issueConfid in issueConfidences" (change)=onIssueConfidenceFilterChange(issueConfid)" id="favoriteCheck1.name">
{{issueConfid.name}}
</md-checkbox>
我想从我的angular 2代码中取消选中(或检查)上面的md-checkbox 例如:angular.getElementById('x')。uncheck(); 如果有任何可行的话,请告诉我们
答案 0 :(得分:1)
您可以将checked
属性添加到模板,然后从组件内部更改其值。
模板
<md-checkbox [checked]="checkBoxChecked" [align]="end" *ngFor="issueConfid in issueConfidences" (change)=onIssueConfidenceFilterChange(issueConfid)" id="favoriteCheck1.name">
{{issueConfid.name}}
</md-checkbox>
组件
checkBoxChecked = false; // or true based on the need
checkCheckBoxProgrammatically(check: boolean) {
this.checkBoxChecked = check ? true : false;
}
修改强>
如果这不起作用,你可以使用ngModel
指令并指定`boolean&#39;变量到它。
<md-checkbox [(ngModel)]="checkBoxChecked" [align]="end" *ngFor="issueConfid in issueConfidences" (change)=onIssueConfidenceFilterChange(issueConfid)" id="favoriteCheck1.name">
{{issueConfid.name}}
</md-checkbox>
可以使用checkCheckBoxProgrammatically(true/false)
方法动态设置该值,而checkBoxChecked
方法又设置<md-checkbox [(ngModel)]="issueConfid.checkBoxChecked" [align]="end" *ngFor="issueConfid in issueConfidences; let i = index" (change)=onIssueConfidenceFilterChange(issueConfid)" id="favoriteCheck1.name">
{{issueConfid.name}} <div (click)="reset(i)">Reset</div>
</md-checkbox>
<div (click)="resetAll()">Reset All</div>
属性。
<强> EDIT_2 强>
issueConfidences
修改您的checkBoxChecked
列表,使其中的所有元素都具有this.issueConfidences = [ {..., checkBoxChecked: true}, ... ,{..., checkBoxChecked: false} ];
reset(index: number) {
this.issueConfidences[index].checkBoxChecked = false;
}
resetAll() {
this.issueConfidences.forEach((issueConfid) => { issueConfid.checkBoxChecked = false; });
}
属性,
undefined
这对你有用吗?