angularangular-reactive-formsdisabled-input

How to disable a input in angular2


In the TS file 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 an input based on true or false.

I tried the following:

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

Solution

  • Try using attr.disabled, instead of disabled

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