[solved] Ionic 4 (press|tap) events

#1

while trying to upgrade from ionic 3.9 to ionic 4-beta i encountered an inconsistency what is not documented in the Breaking changes.

in ionic 3 the event would propagate after a while if the button was long pressed

<button ion-button (press)="doSomething()">long press"</button>

but in ionic 4 no event is fired

<ion-button (press)="doSomething()">long press"</ion-button>

am i mission something?

1 Like
Ionic4 Gestures - GestureController
Ionic v4 drag gesture without hammer.js?
#2

i solved it by adding hammerjs to main.ts file

npm install hammerjs

in src/main.ts


import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

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

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.log(err));

5 Likes
#3

Thanks for this.
I have found it does not work on devices when using using Ionic DevApp but works fine after a build.

#4

Thank’s:grinning:jhkjlhlkjhkjh

#5

This may be off topic, but what is the difference of using the press event vs the click event?

#6

Don’t know if it still applies to ionic 4 but in ionic 3 the (click) event would sometimes cause a lag event event firing if used on a mobile device compared to (tap) event; causing slight UI lag, so I always used (tap)