如何根据在我的 .ts 文件中搜索数组中的值数组来禁用和选中复选框
How to disable and check a checkbox based on searching through an array of values in an array in my .ts file
我有一个带复选框的select。我想禁用并检查字符串数组中存在的那些。
如果值存在于我的 angular .ts 文件中的数组中,我将如何添加 disabled
和 checked
属性。
this.claimNames = any[];
<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"]
我有一个带复选框的select。我想禁用并检查字符串数组中存在的那些。
如果值存在于我的 angular .ts 文件中的数组中,我将如何添加 disabled
和 checked
属性。
this.claimNames = any[];
<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"]