Equivalent to setOnItemLongClickListener in Ionic 2

1

I created a function in which when the user gives a simple click in the item, it 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');
}

Now 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 a long click on the item. On native Android it is possible to do this using the setOnItemLongClickListener method, but I do not know what the equivalent in Ionic would be. What method equivalent to setOnItemLongClickListener in Ionic 2?

    
asked by anonymous 14.02.2017 / 17:06

1 answer

0

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

You need to run the command:

npm install --save ionic-long-press

No 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>
    
17.10.2017 / 21:43