如何基于在我的 .ts 文件中的数组中搜索值数组来禁用和选中复选框

我有这个带有复选框的选择。我想禁用并检查字符串数组中存在的那些。如果值存在于我的角度 .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>


翻过高山走不出你
浏览 131回答 1
1回答

慕尼黑8549860

您可以使用.includes()试试这样:工作演示.html<div class="row container">&nbsp; &nbsp; <div *ngFor="let reno of renoList" class="form-group form-check col-md-3">&nbsp; &nbsp; &nbsp; &nbsp; <input type="checkbox" class="form-check-input" [disabled]="claimNames.includes(reno)" [checked]="claimNames.includes(reno)">&nbsp; &nbsp; &nbsp; &nbsp; <label class="form-check-label">{{reno}}</label>&nbsp; &nbsp; </div></div>.tsrenoList:any[] = ["A", "B", "C"];claimNames:any[] = ["A"]
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript