javascriptangularjsangularjs-ng-disabled

ng-disabled with an expression prevents custom click handlers


I have a directive which basically binds a click event to the button, so after the button is clicked it runs (used a directive so i dont force others to change their ng-click expressions). Anyway the click event inside the directive does not get fired if there was a ng-disabled with a expression. But if the ng-disabled was an explicit expression(ng-disabled="false") it works fine.

https://codepen.io/anon/pen/wxxEbJ

Here is my directive's code that binds the click event:

link: function (scope, element) {
    element.bind('click', function () {
        console.log("click");
    });
}

And my element:

<md-button type="button" ng-disabled="isDiabled" my-directive
           ng-click="save()">
</md-button>

Solution

  • The event wasn't fired after the normal ng-click because of another code that disabled this button so after the ng-click finishes it disables the button so my directive won't catch the event.