gpt4 book ai didi

Angular 9 从不调用 HammerGestureConfig.buildHammer

转载 作者:行者123 更新时间:2023-12-03 20:10:27 25 4
gpt4 key购买 nike

更新到 Angular 9 后,不再使用 Hammer.js。我们扩展了 Angular HammerGestureConfig像下面这样:

import {HammerGestureConfig} from '@angular/platform-browser';
import {Injectable} from '@angular/core';

@Injectable({providedIn: 'root'})
export class HammerConfig extends HammerGestureConfig {

overrides = <any>{
'pan': {
direction: Hammer.DIRECTION_ALL,
threshold: 5
} // override default settings
};

buildHammer(element) {
const recognizers = [];
if (element.hasAttribute('data-hammer-pan')) {
recognizers.push([Hammer.Pan]);
}
if (element.hasAttribute('data-hammer-pan-x')) {
recognizers.push([Hammer.Pan, {direction: Hammer.DIRECTION_HORIZONTAL}]);
}
if (element.hasAttribute('data-hammer-tap')) {
recognizers.push([Hammer.Tap]);
}
if (element.hasAttribute('data-hammer-pinch')) {
recognizers.push([Hammer.Pinch]);
}
if (element.hasAttribute('data-hammer-rotate')) {
recognizers.push([Hammer.Rotate]);
}
if (element.hasAttribute('data-hammer-press')) {
recognizers.push([Hammer.Press]);
}
if (element.hasAttribute('data-hammer-swipe')) {
recognizers.push([Hammer.Swipe]);
}
const hammer = new Hammer.Manager(element, {
recognizers: recognizers,
touchAction: 'auto'
});
return hammer;
}
}
HammerConfig被添加到应用程序模块中。:

  providers: [
{
provide: HAMMER_GESTURE_CONFIG,
useClass: HammerConfig
}
],

据我了解的方法 buildHammer应该被调用,但它永远不会被调用。

可能是什么问题呢?

最佳答案

HammerModule需要导入到 Angular 应用模块。

  imports: [
...
HammerModule
],
providers: [
{
provide: HAMMER_GESTURE_CONFIG,
useClass: HammerConfig
},
...
],
...

ivy: make Hammer support tree-shakable. Previously, in Ivy applications, Hammer providers were included by default. With this commit, apps that want Hammer support must import HammerModule in their root module. (#32203) (de8ebbd)



https://github.com/angular/angular/blob/9.0.0/CHANGELOG.md

关于Angular 9 从不调用 HammerGestureConfig.buildHammer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60380110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com