I'm trying to do an async validation to an email input to check if exists. My directive looks like this:
app.directive('emailExist', ['$http', function ($http) {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, elem, attrs, ctrl) {
ctrl.$asyncValidators.emailExist = function (modelValue) {
return $http({
method: 'POST',
url: '\email-existance',
data: {
email: modelValue
}
}).then(function(res) {
console.log(res)
return (res === 'exist') ? false : true ;
});
}
}
};
}]);
So as far as I understand, asyncvalidators should return true or false based on the validation. (or is it just the sync validators - and if so, what does the async returns? )
Server works and returns me true or false for existance but in both cases my validation stays valid (even when it detects that the email exist)
Please help me!