I already tried to follow the example of other answers from here and I did not succeed!
I created a reactive form (ie, dynamic) and I want to disable some fields at any given time. My form code:
this.form = this._fb.group({
name: ['', Validators.required],
options: this._fb.array([])
});
const control = <FormArray>this.form.controls['options'];
control.push(this._fb.group({
value: ['']
}));
my html:
<div class='row' formArrayName="options">
<div *ngFor="let opt of form.controls.options.controls; let i=index">
<div [formGroupName]="i">
<select formArrayName="value">
<option></option>
<option>{{ opt.controls.value }}</option>
</select>
</div>
</div>
</div>
I reduced the code to facilitate. I want to disable the field of type select. I tried to do the following:
form = new FormGroup({
first: new FormControl({value: '', disabled: true}, Validators.required),
});
not working! Does anyone have a suggestion?
I had the same problem, but calling this.form.controls['name'].disable() did not fixed it because I was reloading my view (using router.navigate()).
In my case I had to reset my form before reloading:
this.form = undefined; this.router.navigate([path]);