app directive spinnerAction parse function parse return restrict link

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
app.directive('spinnerAction', ['$parse', function($parse) {
return {
restrict: 'A',
link: function (scope, element, attrs, formCtrl) {
var fn = $parse(attrs.spinnerAction);
$(element).click(function(event) {
var promise = fn(scope, {$event: event});
if (promise != undefined){
$(element).attr('disabled', true);
$(element).html('<i class="fa fa-spinner fa-spin"></i> ' + $(element).html());
promise.finally(function (){
$(element).find('.fa-spin').remove();
$(element).removeAttr('disabled');
}).then();
}
});
}
}
}]);