V. Aliosha
V. Aliosha

Reputation: 152

Angular 9 dynamically disable form control

What I'm trying to achive is after initiation of the form to disable some controls;

this.someForm= this._fb.group({
  lastName: ['', Validators.required],
  firstName: ['', Validators.required]
});

<input type="text" formControlName="firstName" class="input-field"/>

this.someForm.controls.firstName.disable(); //not works
this.someForm.get('firstName').disable(); //not works

Is there a way to do that without recreating form?

Upvotes: 0

Views: 111

Answers (1)

iamaword
iamaword

Reputation: 1499

this.someForm.get('firstName').disable(); //not works

should work, you just need to update value and validity afterwards:

this.someForm.get('firstName').updateValueAndValidity();

Upvotes: 1

Related Questions