Firstly i have this async validator for angular for password validation and I'm trying to make a delay for the message in html but it doesnt seem to work, how do i need to call it to work.I checked via console.log(control) in the function and it returns the expected result but it still appears instantly on how i called it in HTML code.
I will put sample code here. Here i make the form with the validators.
constructor(fb: FormBuilder)
{
this.form = fb.group({
password: ['', Validators.required,this.asyncValidator],
confirmPassword: ['', Validators.required,this.asyncValidator]
})
}
Here is the validation function.
asyncValidator(control:FormControl):any{
return new Promise(
(resolve) =>{
setTimeout(() => {
if((control.password).length < 6 && (control.password).length > 1)
console.log("true");
console.log("false");
resolve(null);
},2000);
}
);
}
Here is the HTML code that i use in the page to see the delayed message(that doesn't work).
<div class="alert alert-danger"
*ngIf="asyncValidator(this.form.controls.password)">Password too short</div>
How do i need to use the async validator so my message in HTML appears with a 2 secs delay?