I am trying to validate my email address for uniqueness.
With a traditional method, what happens is on every key press the $http
service is being called and lots of database calls are being fired because of this.
I want to make it an on blur event.
I wrote a script and it's working fine but when I test it for the blur event it still fires the $http
service several times. By several times; let's suppose the ajax call already fires for the first time, upon the next go 2 calls will be caught in firebug, and this happens again for the next go making a total of 3 extra calls. This makes 6 calls for every 3.
elem.unbind('input').unbind('keydown').unbind('change');
elem.on('blur', function(){
bindData();
scope.$apply(function () {
ctrl.$setViewValue(elem.val());
});
});
The plunker of the code is here.