我收到此编译错误:
src / app / modules / auth / pages / register / register.component.ts(38,24)中的错误:错误TS2339:属性''pwdMatchValidator'在'typeof CustomValidator类型上不存在'。
它引用的代码是:
import { CustomValidator } from '@helpers/custom-validator';
...
ngOnInit() {
this.form = new FormGroup({
name: new FormGroup({
first: new FormControl('', [Validators.required, Validators.minLength(2)]),
last: new FormControl(''),
}),
email: new FormControl('', [Validators.required, Validators.email]),
password: new FormControl('', Validators.required),
confirmed: new FormControl('', Validators.required),
}, CustomValidator.pwdMatchValidator);
}
我已经在`tsconfig.json>编译器选项>路径中声明了@helpers
:
"paths": {
...
"@helpers/*": ["./src/app/core/helpers/*"],
...
}
CustomValidator
类包含:
import {FormGroup} from '@angular/forms';
export class CustomValidator {
static pwdMatchValidator(frm: FormGroup) {
return frm.get('password').value === frm.get('confirmed').value ? null : {'mismatch': true};
}
}
Webstorm似乎没有找到方法的问题:
我想念什么?
答案 0 :(得分:0)
尝试这样
ngOnInit() {
this.form = new FormGroup({
...
}, {validator: CustomValidator.pwdMatchValidator});
}