title: Angular Custom Async Validator stays in pending state
body: <p>I have a Custom Validator that validates if a user's email is unique or not.</p>
  
  <p><strong>I've searched for related topic on stackoverflow and internet, but no help</strong></p>
  
  <p>when I'm giving input in the form (sending the request), the request stays at pending state and doesnot resolves.</p>
  
  <p>I've tested the backend in postman, its working as expected, the problem is at client or angular side.</p>
  
  <p>The Validation function is as follows:</p>
  
  <pre><code>emailUniqueValidator (control: AbstractControl): Promise&lt;{[key: string]: any}&gt; | Observable&lt;{[key: string]: any}&gt; {
      return new Promise((resolve, reject) =&gt; {
        this.userService.checkEmailUnique(control.value).subscribe((response: Response) =&gt; {
          const body = response.json();
          if (body.found === false) {
            resolve(null); // email is unique
          } else {
            reject({emailUniqueValidator: true}); // email is not unique
          }
        });
      });
    }
  </code></pre>
  
  <p>When i'm changing the form control's value, the pending class appears, but it sticks in forever instead of getting resolved.</p>
  
  <p>I have the email form control as follows: </p>
  
  <pre><code>'email': new FormControl('', [
          Validators.required,
          Validators.email
        ], this.emailUniqueValidator.bind(this)
  ),
  </code></pre>
  
  <p>And my User service is as follows:</p>
  
  <pre><code>checkEmailUnique (email: string): Observable&lt;Response&gt; {
      return this.http.post('http://localhost:3000/user/email', {email}, { withCredentials: true });
    }
  </code></pre>
  
  <p>Why The validator is not resolving in time and staying pending forever?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The following code is getting value from the service just fine, i've checked it by logging the response into the console.</p>
  
  <p>If the email is not present in the database, then it is getting resolved just fine, but if the email is already present, it is throwing an error and the state remains pending.</p>
  
  <pre><code>return new Promise((resolve, reject) =&gt; {
        this.userService.checkEmailUnique(control.value).subscribe((response: Response) =&gt; {
          console.log(response);
          response.json().found ? reject({emailUniqueValidator: true}) : resolve(null);
        }, (error: any) =&gt; reject({emailUniqueValidator: true}));
  });
  </code></pre>