Potato Running Potato Running - 1 month ago 10
AngularJS Question

How to prevent an a element's click event what bind by angular?

I have an a element like this

<a class='btn' ng-click="alert('clicked')"></a>


in js

$scope.alert=(item)=>{alert(item)};


I had tested use ng-disabled but dose not work.
this is my html
this is my html
this is my directive
this is my directive

I have many a element in my project so I want to write a directive like ng-disable how to write it?

Answer

I think this is the way to solve the problem,thank you for all of you to help me sole the problem~

.directive('a', function() {
return {
    restrict: "E",
    replace: true,
    scope: {

    },
    link: function(scope, elem, attr) {
        if (attr['ngDisabled']) {
            elem.unbind('click')
        }
    }
}

})