The question is this. How can I return function(response) result to ngModel.$asyncValidators.usernameAvailable. The url specified in $http.get returns true if user exists and false if not. P.S. response.data returns the correct answer, I checked.
app.directive('usernameAvailableValidator',['$http', function($http){
return{
restrict : 'A',
require : 'ngModel',
link : function(scope, element, attrs, ngModel){
ngModel.$asyncValidators.usernameAvailable = function(username){
return $http.get('/auth/username/exists/'+username).
then(function(response){return response.data});
};
}
}
}])