我升级到了rc.4版本,并且正在尝试使用新的表单API。但是出现了以下错误:
"TypeError: this.form.updateValueAndValidity is not a function"
异常来自于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 });
}
控制台日志的输出是一个名为
FormGroupDirective
的对象,但该对象并没有名为updateValueAndValidity
的方法。上述错误信息对任何人有意义吗?
FormBuilder
类或者只用FormGroup
吗? - Thierry TemplierFormBuilder
类并没有被弃用。我认为这是因为你混合使用了基于模板和基于模型的方法来创建表单。我添加了一个答案... - Thierry Templier