gpt4 book ai didi

javascript - this.form.get 不是一个函数吗?

转载 作者:行者123 更新时间:2023-12-03 02:39:39 27 4
gpt4 key购买 nike

整理一个简单的表单,提交后我收到以下错误:

ERROR TypeError: _this.form.get is not a function
at VM46 vendor.js:29003
at Array.forEach (<anonymous>)
at FormGroupDirective._updateDomValue (VM46 vendor.js:29002)
at FormGroupDirective.ngOnChanges (VM46 vendor.js:28820)
at checkAndUpdateDirectiveInline (VM46 vendor.js:12445)
at checkAndUpdateNodeInline (VM46 vendor.js:13951)
at checkAndUpdateNode (VM46 vendor.js:13894)
at debugCheckAndUpdateNode (VM46 vendor.js:14766)
at debugCheckDirectivesFn (VM46 vendor.js:14707)
at Object.View_FeedformPage_0._co [as updateDirectives] (VM145

我正在运行的函数非常简单...我现在只是想将表单的值记录到控制台(确实如此),但我仍然抛出一个错误,我需要解决这个问题。我的导入/功能如下:

import { Validators, FormBuilder, FormGroup, FormControl } from '@angular/forms';

constructor(public navCtrl: NavController, public navParams: NavParams,
public viewCtrl: ViewController, private formBuilder: FormBuilder,
public storage: Storage) {

this.feedForm = this.formBuilder.group({

description: ['', [Validators.required, Validators.minLength(2), Validators.maxLength(250)]]


});
}

addFeed(){

this.feedForm = this.feedForm.value;
console.log(this.feedForm);

}

HTML 如下:

<form [formGroup]="feedForm" (ngSubmit)="addFeed()">
<ion-item>
<ion-label stacked>Update: </ion-label>
<ion-textarea formControlName="description" placeholder="Leave Comment Here..."></ion-textarea>
</ion-item>
<button ion-button type="submit" [disabled]="!feedForm.valid">Update</button>
</form>

事实上,除了this之外我找不到任何可以引用的东西。告诉我我忽略了一些显而易见的事情。任何见解将不胜感激。

最佳答案

如果您需要记录或发布表单的值,请尝试以下操作:

1-删除this.feedForm = this.feedForm.value;
2- 将 console.log 更改为此 console.log(this.feedForm.getRawValue());

getRawValue 将为您提供所有字段值,即使它们被禁用

关于javascript - this.form.get 不是一个函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48384152/

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