Home > Enterprise >  ngClass not applying the class?
ngClass not applying the class?

Time:05-05

When I do:

           <mat-form-field >
                <mat-label>ID</mat-label>
                <input matInput [(ngModel)]="this.testData">
            </mat-form-field>

It puts a red underline on the field, but when I do:

           <mat-form-field [ngClass]="{'mat-form-field-invalid':true}">
                <mat-label>ID</mat-label>
                <input matInput [(ngModel)]="this.testData">
            </mat-form-field>

It doesn't put the red underline. Am I missing something here?

CodePudding user response:

ngClass doesn't work with <mat-form-field> You can use below syntax-

<mat-form-field [class.mat-form-field-invalid]="true">
  • Related