在 Ionic 2 中使用 NodeJS.Timer 时找不到命名空间 NodeJS [英] Cannot find namespace NodeJS when using NodeJS.Timer in Ionic 2

查看:29
本文介绍了在 Ionic 2 中使用 NodeJS.Timer 时找不到命名空间 NodeJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am attempting to use some code I found on https://github.com/bevacqua/dragula/issues/289#issuecomment-277143172 to my Ionic project.

当我运行代码时,出现错误 Cannot find namespace 'NodeJS' 并且该错误指的是 touchTimeout: NodeJS.Timer;

When I run the code I get an error Cannot find namespace 'NodeJS' and the error refers to touchTimeout: NodeJS.Timer;

如何修改下面的代码以使 NodeJS.Timer 行工作?

How can I adapt the code below to make the NodeJS.Timer line work?

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" 数组.

Add "node" to the "types" array.

示例:

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

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

*if this file does not exist add the specified part to tsconfig.json in root folder.

这篇关于在 Ionic 2 中使用 NodeJS.Timer 时找不到命名空间 NodeJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆