如何在角度 9 中使用 ngx-long-press 处理长按?

How to handle long press with ngx-long-press in angular9?

我在 longPress 在 angular 9 中工作时遇到问题。我在 https://github.com/Gbuomprisco/ngx-long-press 之后导入了模块,我有一个简单的按钮

<button [longPress] (onRelease)="onLongPress()" > </button>

和一个简单的

onLongPress(){
    console.log("long press works");
  }

在我的 ts 文件中。 但是控制台日志永远不会出现。控制台没有错误,只是什么也没发生,所以我的问题是:这个模块应该与 Angular 9 一起工作吗? 如果不是,那么 angular 9 中处理长按的最佳模块是什么?

添加长按指令

import { Directive, ElementRef, EventEmitter, OnDestroy, OnInit, 

Output } from '@angular/core';
import { Clipboard } from '@ionic-native/clipboard';
import { Gesture } from 'ionic-angular/gestures/gesture';
import { Platform } from 'ionic-angular';
declare var Hammer;

@Directive({
  selector: '[longPress]'
})

export class PressDirective implements OnInit, OnDestroy {
  @Output() onLongPressEvent = new EventEmitter();
  el: HTMLElement;
  pressGesture: Gesture;

  constructor(el: ElementRef, private clipboard: Clipboard, private plt: Platform) {
    this.el = el.nativeElement;
    this.onLongPressEvent.emit();
  }

  ngOnInit() {
    if (this.plt.is('ios')) {
      this.pressGesture = new Gesture(this.el);
    } else {
      this.pressGesture = new Gesture(this.el,
        {
          recognizers: [
            [Hammer.Press, { time: 1000 }]
          ]
        });
    }
    this.pressGesture.listen();
    this.pressGesture.on('press', e => {
      this.clipboard.copy(e.target.textContent.trim());
      this.onLongPressEvent.emit();
    });
  }

  ngOnDestroy() {
    this.pressGesture.destroy();
  }
}