1

Kindly see the below object array.i am displaying all group description value along with checkbox. i m trying to disable B and C group but as values are coming dynamic, all checkbox values are getting disabled.how can i disable particular group checkbox here.

[{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>
3
  • Why are you using this? That's doesn't seems to be disabling the checkboxes Commented Feb 8, 2020 at 4:50
  • i have set Boolean flag in typescript. Commented Feb 8, 2020 at 4:54
  • not related to your issue as I am not really familiar with Angular but instead of chaining all the or statements, you can do if ([‘A’, ‘B’, ‘C’, ‘D’].includes(array[i].groupDesc) ... Commented Feb 8, 2020 at 4:58

1 Answer 1

1

You can use a particular object from forEach to modify the property instead of local variable:

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>
Sign up to request clarification or add additional context in comments.

7 Comments

in this case also all checkbox will be disabled right.i need one B and C to be disabled
then why there is A and D in the if block? recheck your if condition!
if i remove also both will not disable at a time . it will take last value. so only D will be disabled
Hi I added Html Code as well. please help me out
@user3363946 Seem working here check this:stackblitz.com/edit/angular-g9fhzs
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.