I have an in which validations are done using angularjs.On submitting the form button is disabled and will enable after getting the response.But button is not getting enabled.For disabling the button I have written a directive.
directives.directive('kcAjaxBtn', function (){
return {
'priority' : 9999,
'restrict' : 'A',
'link' : function(scope, element, attrs) {
element.bind('click', function() {
var currHtml = element.html();
element.attr('disabled', 'disabled').html('Please wait…');
var offMe = scope.$watch(KC_AJAX_COMPLETED, function(){
element.removeAttr('disabled').html(currHtml);
offMe();
});
});
}
}
});
and in services.js it is given like
angular.module('kint.services.general').config([
'$httpProvider',
function($httpProvider){
$httpProvider.interceptors.push(function($q, $rootScope){
return {
'request': function(config) {
return config || $q.when(config);
},
'response' : function(response) {
$rootScope.$broadcast(KC_AJAX_COMPLETE, response);
return response || $q.when(response);
},
'responseError' : function(response) {
$rootScope.$broadcast(KC_AJAX_COMPLETE, response);
switch(response.status) {
case 401:
window.location.reload();
}
return $q.reject(response);
}
};
});
}
]);
But the button is not enabling,if some fields are invalid.How to resolve it?