Javascript 角度-为狭义定义的包含元素抑制广义定义的事件
如果我希望在一个大面板上有一个定义广泛的ng点击,但我希望任何链接标记都只触发链接行为,而不是ng点击,该怎么办?例如:Javascript 角度-为狭义定义的包含元素抑制广义定义的事件,javascript,angularjs,Javascript,Angularjs,如果我希望在一个大面板上有一个定义广泛的ng点击,但我希望任何链接标记都只触发链接行为,而不是ng点击,该怎么办?例如: <div ng-click="doIt()"> <div>Lots of other stuff...</div> <!-- I don't want this or any other links to trigger the ng-click behavior --> <a href='htt
<div ng-click="doIt()">
<div>Lots of other stuff...</div>
<!-- I don't want this or any other links to trigger the ng-click behavior -->
<a href='http://www.amazon.com' target="_blank"></a>
</div>
还有很多其他的东西。。。
您可以将ng单击
附加到您不想受影响的链接,并使用$event.stopPropagation()代码>
在你的控制器里
$scope.dontDoIt = function($event){
$event.stopPropagation();
};
在你的视野之内
<div ng-click="doIt()">
<div>Lots of other stuff...</div>
<!-- I don't want this or any other links to trigger the ng-click behavior -->
<a href='http://www.amazon.com' ng-click="dontDoIt($event)" target="_blank"></a>
</div>
还有很多其他的东西。。。
示例。不太熟悉angular,但是您可以定义自己的javascript事件监听器来调用ng click调用的任何东西吗?好吧,我还是更喜欢将ng click保留在那里,因为它的角度很酷-只是想知道某些内部事物是否可以选择性地覆盖它,阻止事件传播,等等。