I've just started programming with angular and I apologize if the question is simple or asked badly.
I have a custom directive LongPressDirective.ts
import { Directive, ElementRef, OnInit, OnDestroy ,Output , EventEmitter }
from '@angular/core';
import { Gesture } from "ionic-angular/gestures/gesture";
declare let Hammer: any
@Directive({
selector: '[long-press]' // Attribute selector
})
export class LongPressDirective implements OnInit, OnDestroy{
el: HTMLElement;
pressGesture: Gesture;
@Output('long-press') onPressRelease: EventEmitter<any> = new
EventEmitter();
//Hammer: any
constructor(el: ElementRef) {
this.el = el.nativeElement;
console.log('Hello LongPressDirective Directive');
}
ngOnInit() {
//this.pressGesture = new Gesture(this.el);
this.pressGesture = new Gesture(this.el, {
recognizers: [
[Hammer.Press, {time: 1000}]
]
});
this.pressGesture.listen();
this.pressGesture.on('press', (event) => {
console.log('pressed!!');
this.onPressRelease.emit('released');
});
}
ngOnDestroy() {
this.pressGesture.destroy();
}
}
i have import this directive in app.module.ts
in my HTML use this in same mode:
<div #detailB *ngIf = "condition" class = "imgDetailBlur" [ngStyle]="
{'background-image': 'url('path')'}" id="detailB" (long-press)="clearImage()" >
but non working the long-press have try to import che directive in app.module.ts and in the single module but non working