首页 > 解决方案 > TypeError:'this.validator is not a function' on complete not releated error callback

问题描述

这是堆栈跟踪:

 TypeError: this.validator is not a function            app.component.ts:35
  at FormControl.AbstractControl._runValidator (forms.es5.js:2720)
  at FormControl.AbstractControl.updateValueAndValidity (forms.es5.js:2688)
  at new FormControl (forms.es5.js:3011)
  at FormBuilder.control (forms.es5.js:5863)
  at FormBuilder._createControl (forms.es5.js:5905)
  at eval (forms.es5.js:5887)
  at Array.forEach (<anonymous>)
  at FormBuilder._reduceControls (forms.es5.js:5886)
  at FormBuilder.group (forms.es5.js:5845)
  at ProfileSettingsComponent.init (profile-settings.component.ts:318)

打开用户设置页面时出现此错误。正如您在 profile-settings.componenet.ts 中第 318 行的堆栈跟踪中看到的那样,只有 FormBuilder 的第一行。而且我无法理解 FormBuilder 和在 app.componenet.ts 中获取用户对象之间的关系是什么。

app.component.ts:

this.sub = this.userService.getLoggedUser()
  .subscribe(res => {
    console.info('From app: ', res.body.user);
    this.loadVideoChatInviter = true;
  }, err => {
    console.error(err); // line 35
  });

配置文件设置.component.ts:

this.userSettingsToUpdate = this.fb.group({ // line 318
  'firstName': this.user.firstName,
  'lastName': this.user.lastName,
  'email': this.user.email,
  'gender': this.genderItems,
  // ... 
  'newPassword': ['', Validators.minLength(6)],
  'confirmedPassword': ['', Validators.minLength(6)],
  // ...
});

标签: angularangular-reactive-forms

解决方案


推荐阅读