Ion-item-sliding to automatically trigger a button

@smukov Smukov
Sun, 10 Jul 2016 11:50:24 +0000
ionic 2

@smukov wrote:

I was wondering if there is a way to automatically trigger the buttons when using the ion-item-sliding component?

For example, I have the following code:

 <ion-list>
    <ion-item-sliding *ngFor="let cnt of contacts">

      <ion-item (click)="openInvite(cnt)">
{{cnt.getFullName()}}
      </ion-item>

      <ion-item-options side="left">
Accept
      </ion-item-options>

      <ion-item-options side="right">
Dismiss
      </ion-item-options>

    </ion-item-sliding>
  </ion-list>

Could I trigger the acceptInvite(cnt) or dismissInvite(cnt) automatically when a user swipes the row to appropriate side?

I'm aware of the ionDrag event, and the getSlidingPercent() method, and that I could trigger a function if, for example, item.getSlidingPercent() > 1. However, that doesn't handle the case if the user changed his mind and decided to slide the item back to position, if you know what I mean...

In essence, I could use the getSlidingPercent() method only if I could also deduct somehow if the user stopped the drag when the getSlidingPercent() > 1. So is there a way to do this?