[英]Ionic: Avoid redirecting for button in ion-list
情況:
在我的Ionic應用程序中,我正在使用ion-list 。
每個項目都可以滑動以顯示一個按鈕(添加/刪除到收藏夾)。
每個項目都是指向項目頁面的鏈接。
問題是,當我單擊按鈕時,除了觸發適當的功能外,還會激活鏈接。
編碼:
<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>
問題:
有沒有一種方法可以避免在單擊按鈕時退縮? 如果不是官方的方式,您是否知道一些技巧可以實現?
謝謝!
從Ionic 0.9.2開始,有指令ion-stop-event
可以完全滿足您的需求。 它解決了這個問題。
要獲得所需的內容,需要像下面這樣更改代碼:
<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>
在ionic2
3.4.0
使用$event.stopPropagation();
在(點擊)
<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.