这对我有用(这也与ionic4一起使用),我可以使Hammer.js正常工作-也可以与material.angular.io一起使用ionic(在底部)
锤+离子(以及锤+角锤):
npm install --save hammerjs
npm install --save @types/hammerjs
然后
package.json
make sure in dependencies there is this line
"hammerjs": "^2.0.8",
然后
tsconfig.json - added types as seen below
"compilerOptions": {
...
...
"types": [
"hammerjs"
]
}
然后
in app.component.ts (only there)
import 'hammerjs';
然后
in html file (I just took out the first and last < > signs)
div id="myElement"></div
in .ts file
HammerJS网站工作的示例代码
let element2 = document.getElementById('myElement');
let hamming = new Hammer(element2);
hamming.on("panleft panright tap press pressup", function(ev) {
element2.textContent = ev.type +" gesture detected.";
console.log(ev.type +" gesture detected.");
});
锤+离子+材料:使材料锤与离子一起工作
in app.module
import { HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
import { GestureConfig } from '@angular/material';
providers: [
{ provide: HAMMER_GESTURE_CONFIG, useClass: GestureConfig },
]
瞧,您的材质滑块会起作用。
polyfills.ts
使警告消失,这太好了!但是材料设计组件仍然不能正确渲染:/我将在问题描述中包括一个屏幕截图。感谢您一直以来的帮助!