angular – Angualr2错误:无法设置仅具有getter的#的属性值
发布时间:2020-12-17 09:26:51 所属栏目:安全 来源:网络整理
导读:表格看起来像: form [ngFormModel]="myForm" (ngSubmit)="update()" ion-label floatingFirst Name/ion-label ion-input type="text" id="fname" [ngFormControl]="fname" /form 相关课程: export class ProfilePage { myForm: ControlGroup; fname: Abstr
表格看起来像:
<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}); 如果要有选择地仅更新某些字段,或使用setValue并更新所有字段,请使用patchValue (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |