angular 2 : TypeError: this.form.updateValueAndValidity is not a function
angular 2 : TypeError: this.form.updateValueAndValidity is not a function
我升级到 rc.4 并正在尝试使用新的表单-api。这是我得到的:
"TypeError: this.form.updateValueAndValidity is not a function"
异常源自 "form_group_directive.js" 内的文件 angular:
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 语句的输出是 FormGroupDirective
,它只是没有名为 updateValueAndValidity
.
的方法
上述错误信息对任何人都有意义吗?
我认为您不能同时使用模板驱动方法和模型驱动方法。
所以我会使用以下任一方法:
<form *ngIf="showForm" #userForm="ngForm"
(ngSubmit)="userFormSubmit()">
</form>
或:
<form *ngIf="showForm" [formGroup]="userForm"
(ngSubmit)="userFormSubmit()">
</form>
其中 userForm
在组件 class 中用 FormBuilder
或 FormControl
定义。我认为这种方法正是您所需要的...
我升级到 rc.4 并正在尝试使用新的表单-api。这是我得到的:
"TypeError: this.form.updateValueAndValidity is not a function"
异常源自 "form_group_directive.js" 内的文件 angular:
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 语句的输出是 FormGroupDirective
,它只是没有名为 updateValueAndValidity
.
上述错误信息对任何人都有意义吗?
我认为您不能同时使用模板驱动方法和模型驱动方法。
所以我会使用以下任一方法:
<form *ngIf="showForm" #userForm="ngForm"
(ngSubmit)="userFormSubmit()">
</form>
或:
<form *ngIf="showForm" [formGroup]="userForm"
(ngSubmit)="userFormSubmit()">
</form>
其中 userForm
在组件 class 中用 FormBuilder
或 FormControl
定义。我认为这种方法正是您所需要的...