borisyankov/DefinitelyTyped — pull request #2790 by nojaf (2014-09-07 08:50:56+00:00)
Title: updated $asyncValidators

If you read the docs thoroughly (which I didn't at first) the function should return a promise.

An example usage of $asyncValidators inside a link function to check if the e-mail is not taken:

```typescript
function (scope: ng.IScope, elem: JQuery, attrs: ng.IAttributes, ngModel:ng.INgModelController) {

ngModel.$asyncValidators['emailAvailable'] = (modelValue:string, viewValue:string) => {
var value: string = modelValue || viewValue;

var deferred: ng.IDeferred = $q.defer();

accountFactory.isEmailAvailable(value).then(data => {
//the response of this call is OK, the address is free
deferred.resolve(true);
}, err => {
//An 4XX errorcode is given when the e-mail is already taken
deferred.reject("Email exists");
});

return deferred.promise;
};
}
```