我正在尝试对“passwordConfirm”字段进行验证,但出现了一个错误:ERROR TypeError: Cannot read property 'get' of undefined
这是我的代码:
loginForm: FormGroup;
ngOnInit(){
this.loginForm = new FormGroup({
'email': new FormControl(null, [Validators.required, Validators.email]),
'password': new FormControl(null, Validators.required),
'passwordConfirm': new FormControl(null, [Validators.required, this.checkIfMatchingPasswords.bind(this)]),
});
}
checkIfMatchingPasswords() {
return this.loginForm.get('password').value === this.loginForm.get('passwordConfirm').value ? null : { notSame: true} // error
}