gpt4 book ai didi

angular - Angualr2 错误 : Cannot set property value of# which has only a getter

转载 作者:太空狗 更新时间:2023-10-29 17:23:18 26 4
gpt4 key购买 nike

表单看起来像这样:

    <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

关于angular - Angualr2 错误 : Cannot set property value of#<AbstractControl> which has only a getter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38810174/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com