这对我有用(这也适用于 ionic4)
我可以让hammer.js 工作——也可以用material.angular.io 进行离子(在底部)
锤子+离子(锤子+角度):
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 },
]
瞧,您的材质滑块工作正常。