1If you are using a FormGroup, then you should not disable the form in the HTML Template. It will not work if you try to disable in HTML together with FormControl. Instead, it should be done within the FormGroup. Try this:
2
3 template: `
4 <mat-form-field [formGroup]="form">
5 <input matInput placeholder='Name' [formControlName]="formControlName">
6 </mat-form-field>
7 `
8and:
9
10ngOnInit() {
11 this.form = this.fb.group({
12 name: new FormControl({ value: '', disabled: this.disabled })
13 });
14}
15Also...not a big deal but..you should really be doing:
16
17public form: FormGroup;
18instead of:
19
20public form: any;
21Don't forget the import as well
22
23import { FormGroup, FormControl } from '@angular/forms';
24Btw, the name inside of the form group declaration should match whatever you have set in the HTML. So:
25
26<input formControlName="myInputName">
27and
28
29this.form = this.fb.group({
30 myInputName....
31});