Improve this Doc

Error: ngModel:nopromise
No promise

Expected asynchronous validator to return a promise but got '{0}' instead.

Description

The return value of an async validator, must always be a promise. If you want to return a non-promise value, you can convert it to a promise using $q.resolve() or $q.reject().

Example:

.directive('asyncValidator', function($q) {
  return {
    require: 'ngModel',
    link: function(scope, elem, attrs, ngModel) {
      ngModel.$asyncValidators.myAsyncValidation = function(modelValue, viewValue) {
        if (/* I don't need to hit the backend API */) {
          return $q.resolve();     // to mark as valid or
          // return $q.reject();   // to mark as invalid
        } else {
          // ...send a request to the backend and return a promise
        }
      };
    }
  };
})