title: Why this Angular 4 custom validator return a Promise or an Observable? What is the exact logic?
body: <p>I am very new in <strong>Angular 4</strong> and I am not so into <strong>JavaScript\TypeScript</strong> and I have the following doubt about this example found in a tutorial.</p>
  
  <p>It is related to the implementation of a custom form validator but my doubts are more about the <strong>Observable</strong> and <strong>Promise</strong> objects.</p>
  
  <p>So I have something like this:</p>
  
  <pre><code>import {Form, FormControl} from '@angular/forms';
  import {Observable} from 'rxjs/Observable';
  
  export class CustomValidators {
    static asyncInvalidProjectName(control: FormControl): Promise&lt;any&gt; | Observable&lt;any&gt; {
      const promise = new Promise((resolve, reject) =&gt; {
        setTimeout(() =&gt; {
          if (control.value === 'Testproject') {
            resolve({'invalidProjectName': true});
          } else {
            resolve(null);
          }
        }, 2000);
      })
      return promise;
    }
  }
  </code></pre>
  
  <p>The <strong>asyncInvalidProjectName()</strong> method implements the logic of my custom validator.</p>
  
  <p>My doubts are:</p>
  
  <p>1) It seems to me that this method can return a <strong>Promise</strong> object OR an <strong>Observable</strong> object.</p>
  
  <p>Why? It seems to me that it always return a <strong>Promise</strong> object that represents if the input in the form is valid or not. Why in the signature it seems that can return also an <strong>Observable</strong>?</p>
  
  <p>2) What exactly represents a <strong>Promise</strong> object and what are the difference with an <strong>Observable</strong>? (from what I know an Observable is used to react to event change)</p>