我添加了离子长按
npm install --save ionic-long-press
npm install --save hammerjs @types/hammerjs
在我的服务文件夹中创建了一个IonicGestureConfig.ts文件:
import { Injectable } from "@angular/core";
import { HammerGestureConfig } from "@angular/platform-browser";
/**
* @hidden
* This class overrides the default Angular gesture config.
*/
@Injectable()
export class IonicGestureConfig extends HammerGestureConfig {
buildHammer(element: HTMLElement) {
const mc = new (<any>window).Hammer(element);
for (const eventName in this.overrides) {
if (eventName) {
mc.get(eventName).set(this.overrides[eventName]);
}
}
return mc;
}
}
主要提示:
import "hammerjs"; // HAMMER TIME
import { LongPressModule } from 'ionic-long-press';
import { HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
@NgModule({
imports: [
...
],
declarations: [
...,
],
providers: [{provide: HAMMER_GESTURE_CONFIG, useClass: IonicGestureConfig}],
})
export class MyModule {
}
html文件
<ion-button class="inner-button first" (click)="addCmtAmr(p);$event.stopPropagation();" (longClick)="test()" shape="round">+
</ion-button>
./ node_modules / ionic-long-press / fesm5 / ionic-long-press.js中的错误 模块构建失败(来自./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js): TypeError:无法读取undefinedat Object.forEachChild的属性“种类” [ERROR]运行子进程ng时发生错误。
当我在chrome上运行我的项目时,它可以正常工作,但是当我尝试在Android设备上运行时,它崩溃了,并显示了此错误消息。