Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angular 2:TypeError:this.form.updateValueAndValidity不是函数大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在这一点上没有源代码,请随意关注这个问题,我对于角度2开发中的这种痛苦(但必要的)连续弃用模式感到有点厌倦.

所以我升级到rc.4并尝试使用新的forms-api.这就是我得到的:

“TypeError:this.form.updateValueAndValidity不是函数

上述错误消息对任何人都有意义吗?

谢谢

编辑:
好的,源代码毕竟:
异常来自angular中的文件“form_group_directive.js”:

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在组件类中定义的.我认为这种方法是你需要的……

大佬总结

以上是大佬教程为你收集整理的angular 2:TypeError:this.form.updateValueAndValidity不是函数全部内容,希望文章能够帮你解决angular 2:TypeError:this.form.updateValueAndValidity不是函数所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。