如果我想要在大面板上进行广泛定义的ng-click,但我希望任何链接标记仅触发链接行为而不是ng-click,该怎么办?例如:
<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>
答案 0 :(得分:1)
您可以将ng-click
附加到您不希望受到影响的链接,并使用$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>
Fiddle示例。