我試圖做出「passwordConfirm」領域的驗證屬性「GET」,但我得到一個STANGE錯誤:ERROR TypeError: Cannot read property 'get' of undefined
這裏是我的代碼:FormGroup得到字段的值:類型錯誤:無法讀取的不確定
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
}
在您的自定義驗證器中嘗試'if(!this.loginForm){return null}'。 – Alex
什麼都沒有發生。 – sandum
很奇怪,但你可以在checkIfMatchingPasswords()作用域中嘗試this.loginForm.controls ['controlname']。value –