Angular 4: reactive form control is stuck in pending state with a custom async validator

后端 未结 3 1641
无人及你
无人及你 2020-12-31 00:02

I am building an Angular 4 app that requires the BriteVerify email validation on form fields in several components. I am trying to implement this validation as a custom asyn

3条回答
  •  再見小時候
    2020-12-31 00:26

    I've been doing it slightly differently and faced the same issue.

    Here is my code and the fix in case if someone would need it:

      forbiddenNames(control: FormControl): Promise | Observable {
        const promise = new Promise((resolve, reject) => {
          setTimeout(() => {
            if (control.value.toUpperCase() === 'TEST') {
              resolve({'nameIsForbidden': true});
            } else {
    
              return null;//HERE YOU SHOULD RETURN resolve(null) instead of just null
            }
          }, 1);
        });
        return promise;
      }
    

提交回复
热议问题