Skip to content
Advertisement

Error: Expected a validator to return Promise or Observable

I’m trying to do custom validation on Angular 10 but I’m facing the following error.

Expected validator to return Promise or Observable

I just want to return an error to the form if the value doesn’t match the required, here’s my code:

This is the component where my form is

  loginForm() {
    this.form = this.formBuilder.group({
      old_password: ['', Validators.required],
      new_password: ['', Validators.required, Validators.minLength(this.minPw)],
      confirm_password: ['', Validators.required],
    });
  }

Does that type of validation only work with observables or can I do it without being a promise or observable?

Advertisement

Answer

I think there is an error on this line:

new_password: ['', Validators.required, Validators.minLength(this.minPw)],

It should be:

 new_password: ['', [Validators.required, Validators.minLength(this.minPw)]],
Advertisement