I've created a validation directive that verifies a value against an endpoint
App.directive('validate', function(fooService, $q) {
return {
restrict: "A",
require: "ngModel",
link: function(scope, elem, attrs, ngModel) {
ngModel.$asyncValidators.async = function(modelValue, viewValue) {
return fooService.get(viewValue)
.then(function(resp) {
if (!resp.data.success) {
return $q.reject('Not found');
} else {
return true;
}
});
};
}
};
});
I'm looking for a method to store previous results of the call and compare them before making a new AJAX request. Is there a way to achieve this?