我正在尝试使用异步验证程序检查旧密码匹配,即使密码不匹配,也不会返回错误对象。
密码validator.ts
export class PasswordValidators{
static checkOldPassword(service: PasswordService){
return (control: AbstractControl) => {
return service.checkPasswordMatch(control.value).map(response => {
return response ? null : {wrongOldPassword: true};
});
}
}
password.service.ts
export class PasswordService {
actualOldPassword:string = 'abc123';
checkPasswordMatch(oldPassword: string){
return new Observable(observer => {
observer.next(this.actualOldPassword);
}).map( res => res!==oldPassword?0:1);
}
}
变化password.component.ts
constructor(fb: FormBuilder, service: PasswordService) {
this.form = fb.group({
oldPassword: ['', Validators.required,
PasswordValidators.checkOldPassword(service)],
});
}
错误对象
{wrongOldPassword: true}
永远不会返回