内置产品时控件不存在

时间:2019-01-13 16:36:47

标签: angular

当我要在生产环境中构建我的应用程序时出现错误。错误是:

Property 'controls' does not exist on type 'AbstractControl'.

行错误:

userForm.controls['passwords'].controls.repeat_new_password.touched &&
userForm.controls['passwords'].controls.new_password.touched

我的controls

this.userForm = this.formBuilder.group({
      'email': ['', [Validators.required, Validators.email]],
      'passwords': new FormGroup({
          'new_password': new FormControl('', [
              Validators.required
          ]),
          'repeat_new_password': new FormControl('', [
              Validators.required
          ])
      }, AddUserComponent.areEqual),
      'selected' : new FormControl('',[
          Validators.required
      ])
  })

我的areEqual控件:

static areEqual(c: AbstractControl): ValidationErrors | null {
    const keys: string[] = Object.keys(c.value);
    for (const i in keys) {
        if (i !== '0' && c.value[ keys[ +i - 1 ] ] !== c.value[ keys[ i ] ]) {
            return { areEqual: true };
        }
    }
}

我的HTML:

<mat-error class="error-password" *ngIf="
      userForm.controls['passwords'].errors &&
      userForm.controls['passwords'].errors.areEqual &&
      userForm.controls['passwords'].controls.repeat_new_password.touched &&
      userForm.controls['passwords'].controls.new_password.touched
    ">Text error
</mat-error>

运行我的应用程序时,我没有出错。你能帮我吗?

0 个答案:

没有答案