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>
1

1 Answer 1

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()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.