[英]Multiple touch targets in ion-item
I have an ion-list where each ion-item has a href to navigate to the next page (master -> detail). 我有一个离子列表,其中每个离子项目都有一个href导航到下一页(主菜单->详细信息)。 So on-tap event of an ion-item it will navigate to the detail page (as expected). 因此,离子项目的轻按事件将导航到详细信息页面(如预期)。
However, I have a button inside each ion-item that performs an action. 但是,每个离子项目内部都有一个执行动作的按钮。 The issue at hand here is that there are two touch-targets. 这里的问题是有两个触摸目标。 When tapping on the button inside the ion-item both the button's event is fired as well as the surrounding ion-item's event. 当点击离子项目内部的按钮时,按钮的事件以及周围的离子项目的事件都会被触发。
The button inside ion-item uses the ng-click event and the ion-item is fired by the href. ion-item内的按钮使用ng-click事件,href触发ion-item。
I want to be able to tap the button inside the ion-item without firing the href event on the ion-item. 我希望能够在不触发离子项目上的href事件的情况下点击离子项目内的按钮。
Add $event.stopPropogation()
after executing the desired scope function in ng-click
(the deeper one, which is the button in this case). 在ng-click
执行所需的作用域函数后,添加$event.stopPropogation()
(较深的一个,在本例中为按钮)。
Example: 例:
<ion-list>
<ion-item ng-click="someFunction()">
List Item
<button class="button button-small" ng-click="anotherFunction(); $event.stopPropagation();;">List Button</button>
</ion-item>
</ion-list>
For the above example, whenever you click the button, only anotherFunction()
will be executed. 对于上面的示例,每当您单击按钮时,将仅执行anotherFunction()
。 When you click the list item, only someFunction()
will be executed. 当您单击列表项时,将只执行someFunction()
。
Best of luck! 祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.