简体   繁体   English

在Angular中的ng-click事件中触发指令

[英]Fire a directive at ng-click event in Angular

Let say that I have 假设我有

<div ng-controller="MyController" ng-click="MyControllerFunction()" ng-tracking pageevent="button_clicked">click me</div>

I cannot change this structure at all and I need, from my directive ngTracking, catch this pageevent when this button is clicked. 我根本无法更改此结构,单击此按钮后,我需要从指令ngTracking中捕获此pageevent。

Remember, I don't want to touch the controller or even the DOM in this case. 记住,在这种情况下,我不想触摸控制器甚至DOM。

is this possible be done only with the directive? 这只能通过指令来完成吗? If not, is there any other solution? 如果没有,还有其他解决方法吗?

Thank you 谢谢

问题解决了,谢谢。

elm.bind('click', function () { console.log(attrs.pageevent); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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