簡體   English   中英

如何禁用角度 6 中的特定動態復選框?

[英]How to disable particular dynamic checkbox in angular 6?

請參閱下面的對象數組。我正在顯示所有組描述值以及復選框。 我正在嘗試禁用 B 和 C 組,但隨着值的動態變化,所有復選框值都將被禁用。如何在此處禁用特定組復選框。

[{groupId: "4", groupDesc: "A"},
 {groupId: "12", groupDesc: "B"},
 {groupId: "23", groupDesc: "c"},
 {groupId: "34", groupDesc: "D"}]


 for(var i=0;i<array.length;i++)
    {
         if(array[i].groupDesc == B || array[i].groupDesc == c)
            {
                 this.disablecheckbox = true;
            }
    }
<ng-container *ngFor="let value of array;let i = index;">
    <input type="checkbox" pattern="[0-9]{10}" [disabled]="disablecheckbox == true"  value="{{ value.GroupId }}" /><i class="skin"></i><span style ="width: 150px;">{{ value.groupDesc }}</span>
</ng-container>

您可以使用 forEach 中的特定對象來修改屬性而不是局部變量:

for(var i=0;i<array.length;i++)
{
    if(array[i].groupDesc == A || array[i].groupDesc == B || array[i].groupDesc == c || array[i].groupDesc == D)
    {
      array[i].disablecheckbox = true;
    }
}

HTML:

<ng-container *ngFor="let value of array;let i = index;">
    <input type="checkbox" pattern="[0-9]{10}" [disabled]="value.disablecheckbox"  value="{{ value.GroupId }}" /><i class="skin"></i><span style ="width: 150px;">{{ value.groupDesc }}</span>
</ng-container>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM