2017-07-25 28 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

相關問題