表格看起来像:
<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方法.
原文链接:https://www.f2er.com/angularjs/140594.htmlthis.myForm.patchValue({fname: firstName});
如果要有选择地仅更新某些字段,或使用setValue并更新所有字段,请使用patchValue