In the following example:
<li ng-repeat="item in items" ng-click="showItem(item)">
<h3>{{item.title}}</h3>
<button ng-click="remove(item)">Remove</button>
</li>
When I click on the button showItem()
also is invoked due to event bubbling.
I know that I can use $event
to watch for $event.currentTarget
and do $event.stopPropagation()
etc. but this is very ugly.
Btw. I don't want to stop propagation on the button
(In my case the button
is a twitter bootstrap
dopdown/button
- this is just an example)
How do I stop showItem()
from beeing called when I click on the remove
button?
EDIT
The ugly fix would be to have:
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
}
question from:
https://stackoverflow.com/questions/16701092/angularjs-multiple-ng-click-event-bubbling 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…