title: General: asynchonious validation in angular2
body: <p>Since couple evening I've played with form validation in augular2. </p>
  
  <p>All basic cases were easy to implement and they works fine but I stick with asynchronous validation. I have created a very tiny example <a href="http://plnkr.co/edit/Xo8xwJjhlHkXrunzS8ZE" rel="nofollow noreferrer">http://plnkr.co/edit/Xo8xwJjhlHkXrunzS8ZE</a> and it didn't work. </p>
  
  <p>According to test "should fire an event after the status has been updated to pending" from model_spec.ts Registration via creation of control group suppose to work in a way </p>
  
  <pre><code>builder.group({login: ["",Validators.required,validationFuctionWhichReturnsPromise]
  </code></pre>
  
  <p>I spent a full evening to discovered that this code has been released in alfa-46 (and I used alfa-45) and after update depencies the async validation started to work. The feature is  very fresh and is not fully documented but </p>
  
  <p>(for those who haven't tried it yet) Basically async validator is a function which have a Control argument and return a promise which validation result. There are two ways to register a validator. 1) the one which I used in my example and 2)  as a directive which Provide validators via NG_ASYNC_VALIDATORS (See UniqLoginValidator and NgFormControl to see how it work). You can compose more than one validator (not tested yet but functions to do this are in code, see <a href="https://github.com/angular/angular/commit/cf449dd" rel="nofollow noreferrer">https://github.com/angular/angular/commit/cf449dd</a>). </p>
  
  <p>But when I finally reach to up and running validators a new problem arrived. Async validator is perfect to used it in server side validation. But the validation is invoked after each change of model.fe after each keyup. So if we will send request to a server after each key up, it won't be too efficient way ;) I checked how it is done in angular 1 and they is a possibility to debounce validation events.  </p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>How to implement throttle or debounce with async validators? I saw some ideas but none of them were fine (mostly because they need to change angular code itself). Is there any valid way to do this without waiting for new angular release ? </li>
  </ol>
  
  <p>I was thinking about to warping a validator function with debounce (from underscorejs) but it will not work because angular expects to get a valid promise every time. </p>
  
  <p>My second though was that if all event use RxJs under the hood then maybe I can apply debounce on stream of event which is responsible for validation. In model.ts the promise returned from validator is change to observable and a new subscribed is added. We don't have any access to obs(Observable) to apply debounce there. </p>
  
  <ol start="2">
  <li>Is there any way or id to change,easy extend a control over the form validation ?</li>
  </ol>
  
  <p>I spotted a close related problem in <a href="https://stackoverflow.com/questions/32260082/how-to-trigger-form-validators-in-angular2">How to trigger Form Validators in angular2</a></p>
  
  <p>PS there is other issue related to async validators and it is still open <a href="https://github.com/angular/angular/issues/1068" rel="nofollow noreferrer">https://github.com/angular/angular/issues/1068</a></p>