我正在try 使用我在https://github.com/bevacqua/dragula/issues/289#issuecomment-277143172上找到的一些代码来完成我的Ionic项目.

当我运行代码时,我得到一个错误Cannot find namespace 'NodeJS',错误是touchTimeout: NodeJS.Timer;

我如何调整下面的代码以使NodeJS.Timer行正常工作?

import { Directive, ElementRef, HostListener } from '@angular/core';

@Directive({ selector: '[delayDragLift]' })
export class DelayDragLiftDirective {

    dragDelay: number = 200; // milliseconds
    draggable: boolean = false;
    touchTimeout: NodeJS.Timer;

    @HostListener('touchmove', ['$event'])
    // @HostListener('mousemove', ['$event'])
    onMove(e: Event) {
        if (!this.draggable) {
            e.stopPropagation();
            clearTimeout(this.touchTimeout);
        }
    }

    @HostListener('touchstart', ['$event'])
    // @HostListener('mousedown', ['$event'])
    onDown(e: Event) {
        this.touchTimeout = setTimeout(() => {
            this.draggable = true;
        }, this.dragDelay);
    }

    @HostListener('touchend', ['$event'])
    // @HostListener('mouseup', ['$event'])
    onUp(e: Event) {
        clearTimeout(this.touchTimeout);
        this.draggable = false;
    }

    constructor(private el: ElementRef) {
    }
}

推荐答案

打开src/tsconfig.app.json*.

"node"添加到"types"数组中.

例子:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": [
      "node"
    ]
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

*如果此文件不存在,请将指定的零件添加到根文件夹中的tsconfig.json.

Angular相关问答推荐

Angular 16路卫单元测试可观察到的SpyObj属性

HTTP Get请求未发送到提供的URL

如何go 除融合图中的拖尾水印?

在状态更新后是否会再次触发ngrx效果?

[已解决]如何在模块ngDoBootstrap中测试Angular 自定义元素和做覆盖

NGX- colored颜色 Select 器安装出错

Angular 17水化-POST请求同时触发客户端/服务器端,而GET请求仅触发服务器端?

使用forkJoin和mergeMap的正确方式是什么?

MAT折叠面板的动态开启和关闭无法工作

错误:在@angular/core中找不到导出ɵivyEnabled(导入为ɵivyEnabled)

可观察的等待直到另一个可观察的值

错误:在工作区外运行 Angular CLI 时,此命令不可用

Subject.complete() 是否取消订阅所有听众?

无法卸载 angular-cli

Angular 2 - 事件列表

获取从(keypress)angular2按下的键

在Angular 4中以'yyyy-MM-dd'格式获取当前日期

Angular 2 http 没有得到

Angular 2:将外部js文件导入组件

如何升级 Angular CLI 项目?