0

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>
  • Does this answer your question? [Disable Angular 5 Input fields correct way](https://stackoverflow.com/questions/50220643/disable-angular-5-input-fields-correct-way) – Nandita Sharma May 27 '21 at 19:53

1 Answers1

3

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()
Gabriel Sereno
  • 845
  • 1
  • 5
  • 6