Async Validator Throw Expected validator for returning a promise or observation

I tried to confirm the password with a password. I did this according to Async authentication standard. But I'm curious that this does not work and throws me the following error. Please let everyone know how to resolve this error.

The expected validator to return a promise or observation.

Here is my code.

Call Validators:

cPass: ['', Validators.compose([ Validators.required, Validators.maxLength(32), Validators.minLength(10) ]), this.validPassword.bind(this) ] 

Custom validation function:

 validPassword(control: AbstractControl) { const isEqual = Observable.of(this.password == control.value); return isEqual ? { valid : true } : null; } 
+5
source share
1 answer

The error speaks for itself:

The expected validator to return a promise or observation.

You return 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

+8
source

Source: https://habr.com/ru/post/1269630/


All Articles