2017-07-25 103 views
3

我正在尝试将我在https://github.com/bevacqua/dragula/issues/289#issuecomment-277143172上找到的一些代码用于我的Ionic项目。当在Ionic 2中使用NodeJS.Timer时找不到名称空间NodeJS

当我运行代码我得到一个错误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) { 
    } 
} 
+0

你解决了吗? – Alberick0

回答

1

打开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

相关问题