Form looks something like:
<form [ngFormModel]="myForm" (ngSubmit)="update()">
<ion-label floating>First Name</ion-label>
<ion-input type="text" id="fname" [ngFormControl]="fname">
</form>
Associated class:
export class ProfilePage {
myForm: ControlGroup;
fname: AbstractControl;
constructor(private _profile: Profile, fb: FormBuilder) {
this.myForm = fb.group({
'fname': ['', Validators.compose([Validators.required, Validators.minLength(2), firstCharacter])]
});
this.fname = this.myForm.controls['fname'];
Promise.all([this._profile.firstname, this._profile.lastname, this._profile.base64Image]).then(values => {
this.fname.value = values[0];
// this.lname.value = values[1];
});
}
Error received:
EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot set property value of #<AbstractControl> which has only a getter
I think you should use setValue or patchValue methods of FormGroup.
this.myForm.patchValue({fname: firstName});
use patchValue if you want to selectively update only certain fields, or setValue and update all
Try:
(this.fname as Control).updateValue(values[0]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With