我选中此复选框。我想禁用并检查字符串数组中存在的那些。如果我的angular .ts文件中的数组中存在值,我该如何同时添加disabled
和checked
属性。
this.claimNames =任何[];
<div class="row container">
<div *ngFor="let reno of renoList" class="form-group form-check col-md-3">
<input type="checkbox" class="form-check-input" disabled checked>
<label class="form-check-label">{{reno}}</label>
</div>
</div>
您可以使用.includes()
尝试这样:
。html
<div class="row container">
<div *ngFor="let reno of renoList" class="form-group form-check col-md-3">
<input type="checkbox" class="form-check-input" [disabled]="claimNames.includes(reno)" [checked]="claimNames.includes(reno)">
<label class="form-check-label">{{reno}}</label>
</div>
</div>
。ts
renoList:any[] = ["A", "B", "C"];
claimNames:any[] = ["A"]