Use asynchronous validator if the validation can not be computed immediately, but is provided through a callback. The widget automatically shows a spinning indicator while the validity of the widget is computed. This validator caches the result.
<input type="text" ng:validate="asynchronous:validate[:update]"/>
angular.validator.asynchronous(value, validate[, update])
value – {string} –
value to validate
validate – {function(inputToValidate,validationDone)} –
function to call to validate the state of the input.
update(optional=noop) – {function(data)} –
function to call when state of the validator changes
<script> function MyCntl(){ this.myValidator = function (inputToValidate, validationDone) { setTimeout(function(){ validationDone(inputToValidate.length % 2); }, 500); } } </script> This input is validated asynchronously: <div ng:controller="MyCntl"> <input name="text" ng:validate="asynchronous:myValidator"> </div>
it('should change color in delayed way', function(){ var textBox = element('.doc-example-live :input'); expect(textBox.prop('className')).not().toMatch(/ng-input-indicator-wait/); expect(textBox.prop('className')).not().toMatch(/ng-validation-error/); input('text').enter('X'); expect(textBox.prop('className')).toMatch(/ng-input-indicator-wait/); sleep(.6); expect(textBox.prop('className')).not().toMatch(/ng-input-indicator-wait/); expect(textBox.prop('className')).toMatch(/ng-validation-error/); });