Answer the question
In order to leave comments, you need to log in
How to create an asynchronous form validator?
I want to create an asynchronous validator using an observable, but I don't know if this is possible. Now it only turns out to be done through promises, but that's not it.
//вызов
this.userForm = fb.group({
firstName : null,
surname : null,
username : null,
email : [null, Validators.compose([Validators.required, Validators.minLength(5)]), ValidationService.uniqueEmail],
password : '',
role : '',
state : '',
phone : '',
})
static uniqueEmail(control: FormControl) {
return Promise.resolve().then(() => {
setTimeout(() => {
console.log('ttt');
if(control.value == '[email protected]') {
return null;
} else {
return { 'notUnique' : true };
}
}, 2000);
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question