I have tried to confirm the password with password value. I have done as per Async validator standard. But I am wondering it's not working and throw me the following error. Please tell anyone how to solve this error.
Expected validator to return Promise or Observable.
Here is my code.
Call Validators:
cPass: ['', Validators.compose([
Validators.required,
Validators.maxLength(32),
Validators.minLength(10)
]),
this.validPassword.bind(this)
]
Custom Validation funciton:
validPassword(control: AbstractControl) {
const isEqual = Observable.of(this.password == control.value);
return isEqual ? { valid : true } : null;
}
The error speaks for itself:
Expected validator to return Promise or Observable.
You're returning object|null
in your function
.
Just change it to:
validPassword(control: AbstractControl) {
return observableOf('12345678910' === control.value).pipe(
map(result => result ? { invalid: true } : null)
);
}
STABKBLITZ DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With