Ionic long press event on cards

戏子无情 提交于 2021-02-08 04:36:20

问题


How can I set a long press event to a card in Ionic to fire up action sheet for the specific card. Just help me in binding this long press event in ionic


回答1:


You can use the following npm package: https://www.npmjs.com/package/ionic-long-press

This plugin should be compatible with Ionic and Angular 7+

Import the module:

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

@NgModule({
    imports: [
        ...
        LongPressModule
        ...
    ]
})

And use in your template:

<button
  ion-button
  ion-long-press
  [interval]="400"
  (pressed)="pressed()"
  (longPressed)="active()"
  (pressEnded)="released()"
></button>



回答2:


Ionic 4 Gestures: Install HammerJs.

npm install hammerjs

Inside: src/main.ts

/**
 * Hammerjs must be imported for gestures
 */
import 'hammerjs';

You can do something like:

<ion-card (press)="tapEvent($event)">
  <ion-item>
    Tapped: {{tap}} times
  </ion-item>
</ion-card>

In .ts

tapEvent(e){
    console.log(e);
    this.tap++;
}


来源:https://stackoverflow.com/questions/57995177/ionic-long-press-event-on-cards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!