【发布时间】:2018-02-19 20:43:24
【问题描述】:
我创建了一个装饰器来帮助我处理桌面/移动事件
import { HostListener } from '@angular/core';
type MobileAwareEventName =
| 'clickstart'
| 'clickmove'
| 'clickend'
| 'document:clickstart'
| 'document:clickmove'
| 'document:clickend'
| 'window:clickstart'
| 'window:clickmove'
| 'window:clickend';
export const normalizeEventName = (eventName: string) => {
return typeof document.ontouchstart !== 'undefined'
? eventName
.replace('clickstart', 'touchstart')
.replace('clickmove', 'touchmove')
.replace('clickend', 'touchend')
: eventName
.replace('clickstart', 'mousedown')
.replace('clickmove', 'mousemove')
.replace('clickend', 'mouseup');
};
export const MobileAwareHostListener = (
eventName: MobileAwareEventName,
args?: string[],
) => {
return HostListener(normalizeEventName(eventName), args);
};
问题是当我尝试使用--prod 进行编译时,出现以下错误
typescript error
Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing
the function or lambda with a reference to an exported function (position 26:40 in the original .ts file),
resolving symbol MobileAwareHostListener in
.../event-listener.decorator.ts, resolving symbol HomePage in
.../home.ts
Error: The Angular AoT build failed. See the issues above
怎么了?我该如何解决?
【问题讨论】:
-
问题之一是我不能使用
const foo = () =>,使用function导出工作。但是还有一个问题,我不能使用typeof,为什么?有什么办法吗? -
您知道 Hostlistener 装饰器能够处理移动事件并将鼠标事件转换为触摸事件吗?你只需要导入'hammerjs。
-
@cyrix 你能解释一下hammerjs 究竟是如何解决这个问题的吗?
标签: angular typescript