问题
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