angular 2:TypeError:this.form.updateValueAndValidity不是函
发布时间:2020-12-17 17:56:33 所属栏目:安全 来源:网络整理
导读:在这一点上没有源代码,请随意关注这个问题,我对于角度2开发中的这种痛苦(但必要的)连续弃用模式感到有点厌倦. 所以我升级到rc.4并尝试使用新的forms-api.这就是我得到的: “TypeError:this.form.updateValueAndValidity不是函数” 上述错误消息对任何人都
在这一点上没有源代码,请随意关注这个问题,我对于角度2开发中的这种痛苦(但必要的)连续弃用模式感到有点厌倦.
所以我升级到rc.4并尝试使用新的forms-api.这就是我得到的: “TypeError:this.form.updateValueAndValidity不是函数” 上述错误消息对任何人都有意义吗? 谢谢 编辑: FormGroupDirective.prototype.ngOnChanges = function (changes) { this._checkFormPresent(); if (collection_1.StringMapWrapper.contains(changes,'form')) { var sync = shared_1.composeValidators(this._validators); this.form.validator = validators_1.Validators.compose([this.form.validator,sync]); var async = shared_1.composeAsyncValidators(this._asyncValidators); console.log('from within angular:---------------------------------------------------------------------------------------------------'); console.log(this.form); this.form.asyncValidator = validators_1.Validators.composeAsync([this.form.asyncValidator,async]); this.form.updateValueAndValidity({ onlySelf: true,emitEvent: false }); } console.log-statement的输出是一个“FormGroupDirective”,它没有一个名为“updateValueAndValidity”的方法 解决方法
我不认为你可以同时使用模板驱动的方法和模型驱动的方法.
所以我会使用以下两种方法: <form *ngIf="showForm" #userForm="ngForm" (ngSubmit)="userFormSubmit()"> </form> 要么: <form *ngIf="showForm" [formGroup]="userForm" (ngSubmit)="userFormSubmit()"> </form> 其中userForm是使用FormBuilder或FormControl在组件类中定义的.我认为这种方法是你需要的…… (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |