programmer0892
programmer0892

Reputation: 21

Why is Disabled not working in following html/angular code?

In the following code,i am using [disabled] for disabling the name field whenever the operation is edit,however its not working. It does work if i change it to [readonly]="operationType == 'Edit'"...can anyone help me why disabled is not working? thank you.

<mat-form-field style="width: 320px !important;background-color: white;" appearance="outline">
        <mat-label>NAME</mat-label>
        <input matInput type="text" style="text-transform: uppercase;" maxlength="6"
          formControlName="name" 
          oninput="this.value = this.value.toUpperCase()"
          [disabled]="operationType == 'Edit'" />
        <mat-error *ngIf="hasError('name', 'required')">name is required</mat-error>
      </mat-form-field>

Upvotes: 0

Views: 199

Answers (1)

Gabriel Sereno
Gabriel Sereno

Reputation: 855

It won't disable because you need to do it in FormGroup:

this.formGroup.disable()

It'll disable all fields for you

If you want to disable a specific control, you can do like this:

this.formGroup.get("nameOfControl").disable()

Upvotes: 3

Related Questions