Only swipe events available for IonItemSliding by default. So, here the idea to add click event.
Last active
January 29, 2019 19:22
-
-
Save ihsanberahim/b48f2bf659aafc55f629dac6c32dd52a to your computer and use it in GitHub Desktop.
IONIC3 - Trigger IonItemSliding using click event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Generated template for the EventListingPage page. | |
See http://ionicframework.com/docs/components/#navigation for more info on | |
Ionic pages and navigation. | |
--> | |
<ion-header> | |
<ion-navbar> | |
<ion-title>My Page</ion-title> | |
</ion-navbar> | |
</ion-header> | |
<ion-content> | |
<ion-list> | |
<ion-item-sliding #slidingItem *ngFor="..."> | |
<ion-item #item (click)="openOption(slidingItem, item)"> | |
Item | |
</ion-item> | |
<ion-item-options side="right" (click)="closeOption()"> | |
<a [href]="..." icon-left clear ion-button item-right> | |
<ion-icon name="call"></ion-icon> | |
Open Url | |
</a> | |
</ion-item-options> | |
</ion-item-sliding> | |
</ion-list> | |
</ion-content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { ..., Item, ItemSliding } from 'ionic-angular'; | |
/** | |
* Generated class for the EventListingPage page. | |
* | |
* See http://ionicframework.com/docs/components/#navigation for more info | |
* on Ionic pages and navigation. | |
*/ | |
@IonicPage() | |
@Component({ | |
... | |
}) | |
export class MyPage { | |
... | |
activeItemSliding: ItemSliding = null; | |
constructor(...) { | |
... | |
} | |
ionViewDidLoad() { | |
... | |
} | |
... | |
openOption(itemSlide: ItemSliding, item: Item) { | |
console.log('opening item slide..'); | |
if(this.activeItemSliding!==null) //use this if only one active sliding item allowed | |
this.closeOption(); | |
this.activeItemSliding = itemSlide; | |
let swipeAmount = 194; //set your required swipe amount | |
itemSlide.startSliding(swipeAmount); | |
itemSlide.moveSliding(swipeAmount); | |
itemSlide.setElementClass('active-options-right', true); | |
itemSlide.setElementClass('active-swipe-right', true); | |
item.setElementStyle('transition', null); | |
item.setElementStyle('transform', 'translate3d(-'+swipeAmount+'px, 0px, 0px)'); | |
} | |
closeOption() { | |
console.log('closing item slide..'); | |
if(this.activeItemSliding) { | |
this.activeItemSliding.close(); | |
this.activeItemSliding = null; | |
} | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
please update this with ionic 4.0.0 now!
Thanks.