Equivalent to setOnItemLongClickListener in Ionic 2

Asked

Viewed 74 times

1

I created a function in which when the user gives a click simple in item, shows a Toast, an alert, on the screen with the name of this item:

Function in my file .ts:

itemSelected(item: string) {
    this.toastCtrl.showToast("Selected Item: " + item, 'bottom');
}

Already the button is set this way:

<button ion-item *ngFor="let item of people" (click)="itemSelected(item)">
  {{ item.firstname }}
</button>

This works normally, however now I would like to create a list of options when the user makes one click long in the item. On native Android it is possible to do this using the method setOnItemLongClickListener, but I don’t know what the equivalent would be in Ionic. Which method is equivalent to setOnItemLongClickListener in Ionic 2?

  • sao would be the on-hold ?

  • @Neuberoliveira I don’t know. Yeah?!

  • http://ionicframework.com/docs/api/directive/onHold/

  • At least in Ionic 1 is, is just testing.

  • Tested: it doesn’t work.

1 answer

0

In Ionic 2, you can do this with the Ionic-long-press.

You need to rotate the command:

npm install --save ionic-long-press

On app.module.ts:

import { LongPressModule } from 'ionic-long-press';

imports: [
  LongPressModule,
  IonicModule.forRoot(MyApp),
],

In your html:

<button ion-button (click)="init()" ion-long-press 
     [interval]="4000" (onPressStart)="pressed()" 
     (onPressing)="mantendoPessionado()"
     (onPressEnd)="released()" color="danger">
</button>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.