Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度-为狭义定义的包含元素抑制广义定义的事件_Javascript_Angularjs - Fatal编程技术网

Javascript 角度-为狭义定义的包含元素抑制广义定义的事件

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

如果我希望在一个大面板上有一个定义广泛的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='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保留在那里,因为它的角度很酷-只是想知道某些内部事物是否可以选择性地覆盖它,阻止事件传播,等等。