How to disable a input in angular2

Tampa picture Tampa · Feb 11, 2017 · Viewed 311.2k times · Source

In ts is_edit = true to disable...

<input [disabled]="is_edit=='false' ? true : null" id="name" type="text" [(ngModel)]="model.name" formControlName="name" class="form-control" minlength="2">

I just simply want to disable a input based on true or false.

I tried following:

[disabled]="is_edit=='false' ? true : null"
[disabled]="is_edit=='true'"
[disabled]="is_edit"

Answer

fedtuck picture fedtuck · May 3, 2017

Try using attr.disabled, instead of disabled

<input [attr.disabled]="disabled ? '' : null"/>