在下面的例子中:
<li ng-repeat="item in items" ng-click="showItem(item)">
<h3>{{item.title}}</h3>
<button ng-click="remove(item)">Remove</button>
</li>
当我点击按钮showItem()
时,由于事件冒泡也会被调用。
我知道可以使用$event
来监听$event.currentTarget
并执行$event.stopPropagation()
等操作,但这很丑陋。
顺便说一下,我不想在button
上停止传播(在我的情况下,button
是一个twitter bootstrap
的dopdown/button
- 这只是一个示例)
如何停止在我点击remove
按钮时调用showItem()
?
编辑: 丑陋的解决方法是:
function remove(item,$event){
$event.originalEvent.prevent = true;
// rest of the code
}
function showItem(item,$event){
if($event.originalEvent.prevent)return;
// rest of the code
}