Reputation: 21
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
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