title: Angular validator to check availability
body: <p>I'm creating a Reactive Form in angular to register some devices. In this form I ask for a serial number, and I want to check if this serial number is already registered in my database.</p>
  
  <p>When I type in the input form it activates the function serialNumAvailability to display or not a message. This function calls a service function called checkSerialNumAvailability which send a get request to my back-end. I made some console.log and used Postman to test the get request, and it seems to work fine on the back-end side. But at the moment I type one character in the input field, I go back to my home page, and I can't understand why... </p>
  
  <p>Here is my HTML template verification:</p>
  
  <pre><code>&lt;input formControlName="serialNum" type="text" class="form-control" placeholder="Ex: SL07101-BL" name="serialNum" required&gt;
  &lt;div *ngIf="f.submitted " class="help-block mt-2 text-danger" i18n&gt; Serial Number is required&lt;/div&gt;
  &lt;div *ngIf="serialNum?.value.errors.serialNumAvailability" i18n&gt; Serial Number already registered&lt;/div&gt;
  </code></pre>
  
  <p>Then my component function serialNumAvailability :</p>
  
  <pre><code>serialNumAvailability(control: FormControl) {
  
      return Observable.timer(500).switchMap(() =&gt; {
  
        return this.portalService.checkAvailabilitySerialNum(control.value)
          .map(res =&gt; {
            if (res &amp;&amp; res.length == 1 &amp;&amp; res[0].serialNum) {
              console.log("ON RENVOIE TRUE");
              return { serialNumAvailability: true};
            }
            console.log("ON RENVOIE NULL");
            return null;
          });
      });}
  </code></pre>
  
  <p>My service function :</p>
  
  <pre><code>checkAvailabilitySerialNum(term: string): Observable&lt;Portal[]&gt; {
      let portals: Portal[];
  
      if (!term.trim()) {// if search is empty
        return Observable.of([]);
      }
  
      return this.http.get&lt;Portal[]&gt;(this.serverURL + `portal/?serialNum=${term}`)
      .map(Portals =&gt; Portals.filter(portals =&gt; portals.serialNum === term)
      );
    }
  </code></pre>
  
  <p>And finally the Node side :</p>
  
  <pre><code>router.get('/',
      function (req, res) {
          console.log("ON RENTRE BIEN DANS LA FONCTION : " + req.query.serialNum);
              return models.portals.findAll({
                  attributes: ['serialNum'],
                  where: {
                      serialNum: req.query.serialNum
                  }
              }).then((serialNums) =&gt; {
                  if (serialNums) {
                      serialNums = serialNums.map((serialNum) =&gt; {
                          serialNum = serialNum.toJSON();
                          console.log(serialNum);
                          return serialNum;
                      })
                  }
                  console.log("ON FAIT RES.SEND DE "+serialNums);
                  res.send(serialNums);
              })
      })
  </code></pre>
  
  <p>I don't know why I'm redirected, if someone has encountered this problem, thanks for support :)</p>