表格看起来像:
<form [ngFormModel]="myForm" (ngSubmit)="update()">
<ion-label floating>First Name</ion-label>
<ion-input type="text" id="fname" [ngFormControl]="fname">
</form>
相关类:
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];
});
}
收到错误:
EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot set property value of #<AbstractControl> which has only a getter
我认为你应该使用 FormGroup 的 setValue 或 patchValue 方法。
this.myForm.patchValue({fname: firstName});
如果您想有选择地仅更新某些字段,请使用 patchValue,或者使用 setValue 并更新所有字段
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)