I have a simple form and i have to validate many input fields on ajax call.
Many of input fields are reusable so i have used directive for them.
<input name="UserName"
type="text"
user-name-unique
ng-model="UserName"
required
/>
Directive function :
elem.on('blur', function(evt) {
scope.$apply(function() {
var data = { 'username': elem.val() };
var ajaxConfiguration = { method: 'POST', url: 'url', data: data };
async(ajaxConfiguration).success(function(data, status, headers, config) {
ctrl.$setValidity('userNameUnique', !data.IsSuccess);
});
});
});
Similarly i have many directives which validates the input using ajax call.
How to make my submit function to wait for all my ajax requests to complete?