Search code examples
angularangular4-forms

How to disable the input text based on *ngif in angular4


how to disable textbox if the ngifcondition satisfies on text box field.

Below didnt work for me


<input [ngClass]="{'disbaled' : !isprecheck}" type="text" class="form-control" id="title" name="title"
                           [(ngModel)]="stunt.title" #Title="ngModel" required minlength="1" maxlength="255">

Solution

  • If you use declarative forms as now use the disabled attribute like [disabled]="condition" but if you are learning angular I suggest to take a look at reactive forms they are way more powerful: https://angular.io/guide/reactive-forms