While attempting to modify the button text based on the promise status, I created a custom directive for this purpose.
Below is the code snippet for my custom directive:
.directive('myDir',function(){
return {
scope: {
myDir: '&',
afterValue: '@',
beforeValue:'@',
ngDisable:'=',
},
link: function ($scope, element, attrs) {
element[0].innerHTML=$scope.beforeValue;
element.bind('click',function(){
console.log(element);
element[0].innerHTML=$scope.afterValue;
element[0].className+="disabled";
element[0].disabled='true'
$scope.myDir();
//success i would like to change the status here
})
}
}
})
Here is the corresponding controller code:
.controller('myCtrl',[function(){
var vm = this;
console.log("MYCTRL");
vm.fun= function(){
//promise running here
}
}])
Furthermore, you can access the working example via this Plnkr link : https://plnkr.co/edit/Qj9GG2?p=templates/
I am currently facing difficulty in capturing the success of the promise in the directive.