简体   繁体   English

离子:避免重定向离子列表中的按钮

[英]Ionic: Avoid redirecting for button in ion-list

THE SITUATION: 情况:

In my Ionic app i am using ion-list . 在我的Ionic应用程序中,我正在使用ion-list

Each item can swipe to reveal a button (add/remove to favorites). 每个项目都可以滑动以显示一个按钮(添加/删除到收藏夹)。

Each item is a link to the item page. 每个项目都是指向项目页面的链接。

The problem is that when i click the button, besides triggering the proper function it also activate the link. 问题是,当我单击按钮时,除了触发适当的功能外,还会激活链接。

THE CODE: 编码:

<ion-list can-swipe="true" class="list" ng-repeat="project in project_list">

    <ion-item class="item-content item-text-wrap" ng-click="go_to_project_page( project )">

        <h1 class="custom_h1">{{project.name}}</h1>

        <ion-option-button class="button-small button-balanced" ng-if="current_project_list_type != 'favorites'" ng-click="project_favorite_add( project.project_id )">
            Mark as favorite
        </ion-option-button>

        <ion-option-button class="button-small button-assertive" ng-if="current_project_list_type == 'favorites'" ng-click="project_favorite_remove( project.project_id )">
            Remove from favorites
        </ion-option-button>

    </ion-item>

</ion-list>

THE QUESTION: 问题:

There is a way to avoid redicting when clicking on the button? 有没有一种方法可以避免在单击按钮时退缩? If not an official way, do you know some tricks how this can be achieved? 如果不是官方的方式,您是否知道一些技巧可以实现?

Thank you! 谢谢!

Since Ionic 0.9.2 there is the directive ion-stop-event that does exactly what you need I suppose. 从Ionic 0.9.2开始,有指令ion-stop-event可以完全满足您的需求。 It solves this issue. 它解决了这个问题。

To get what you want you need to alter your code like so: 要获得所需的内容,需要像下面这样更改代码:

    <ion-option-button ion-stop-event="click" class="button-small button-balanced" ng-if="current_project_list_type != 'favorites'" ng-click="project_favorite_add( project.project_id )">
        Mark as favorite
    </ion-option-button>

    <ion-option-button ion-stop-event="click" class="button-small button-assertive" ng-if="current_project_list_type == 'favorites'" ng-click="project_favorite_remove( project.project_id )">
        Remove from favorites
    </ion-option-button>

In ionic2 3.4.0 use $event.stopPropagation(); ionic2 3.4.0使用$event.stopPropagation(); in (click) 在(点击)

<ion-item (click)="firstView()">
        <ion-icon name="trash" item-end (click)="secondView();$event.stopPropagation();"></ion-icon>
        <h2>{{name}}</h2>
        <h3>{{type}}</h3>
        <p>{{description}}</p>

</ion-item>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM