I have a ion-select list. Now, when i select an option, i am triggering one callback using (ionSelect). But i want to trigger another callback when user double clicks on an option. My code is:
imported in src/app/app.module.ts
import { PressGestureDirective } from ‘…/directives/press-gesture/press-gesture’;
and declared in the declarations
PressGestureDirective,
import {Directive, ElementRef, OnInit, OnDestroy, Output, EventEmitter} from '@angular/core';
import {Gesture} from 'ionic-angular/gestures/gesture';
declare var Hammer; /* declare as u might get error hammer not found though its loaded already by ionic when we use gesture*/
/*
Generated class for the PressGesture directive.
See https://angular.io/docs/ts/latest/api/core/index/DirectiveMetadata-class.html
for more info on Angular 2 Directives.
*/
@Directive({
selector: '[dblTap]' // Attribute selector
})
export class PressGestureDirective implements OnInit, OnDestroy{
el: HTMLElement;
pressGesture: Gesture;
@Output() dblTap: EventEmitter<any> = new EventEmitter();
constructor(el: ElementRef) {
this.el = el.nativeElement;
}
ngOnInit() {
this.pressGesture = new Gesture(this.el, {
recognizers: [
[Hammer.Tap, {taps: 2}]
]
});
this.pressGesture.listen();
this.pressGesture.on('tap', e => {
this.dblTap.emit(e);
})
}
ngOnDestroy() {
this.pressGesture.destroy();
}
}