Search code examples
angularangular7

How to make checkbox disabled on condition in angular?


previously i have used Boolean property to make checkbox disabled.

here is what i tried so far.

app.component.ts
---------------
 ReadOnly: boolean;

  ngOnInit() {
    this.ReadOnly = true;
  }

app.component.htmt
------------------
<input type="checkbox" [disabled]="ReadOnly">

{ 
         "id":1,
         "category":"cc",
         "sortOrder":"1",
         "active":"Y",
         "Products":[ 
            { 
               "id":100,
               "backEndName":"DDA",
               "sortOrder":"1",
               "active":"N"
            }
         ]
      }

Now i need to use active condition make field disable. how can i do the same?


Solution

  • Try like this:

    <input type="checkbox" [disabled]="item.active == 'N'">