简体   繁体   中英

AngularJS Directive Remove ngClick attr and event listener

I'm having an issue where in some situations I need to remove the ng-click="" attribute completely from an element depending on a few scenarios. I'm struggling to figure out how to remove the event listener after I remove the ngClick attribute. Even though the ngClick is removed, the event listener is still on that element and executes the ng-click regardless if it isn't even there.

I'm removing the ngClick attribute in a "link" AngularJS directive. Any idea what I should do?

您可以维护一个标志isClickEnabled表示启用或禁用ng-click

ng-click="isClickEnabled && callMyMethod()"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM