【问题标题】:Module has no exported member NumpadTouchControl模块没有导出成员 NumpadTouchControl
【发布时间】:2017-05-20 04:38:35
【问题描述】:

我正在使用 Angular 1.4.9 和 TypeScript 开发自定义指令。该指令已完成,但我正在尝试将其导入我的 app.ts,以便我可以注册它。这就是我卡住的地方。

我的指令看起来像这样

export module Helloworld{
    export class NumpadTouchControl implements ng.IDirective{

    }
}

我的 app.ts 是这样的

import { NumpadTouchControl } from './directives/numpadTouchControl';

module Helloworld {

}

在我的 app.ts 的第一行它说:Module ... has no exported member 'NumpadTouchControl'。我怎样才能使我的导入工作?

我没有使用 webpack 或 browserify。

【问题讨论】:

    标签: angularjs typescript


    【解决方案1】:

    你不需要外部的export module HelloWorld{。每个文件都隐含地是一个模块。

    如果你的第一个文件只是

    export class NumpadTouchControl implements ng.IDirective{
        ...
    }
    

    这应该会照顾它。

    【讨论】:

    • 当我这样做时,错误消失了,但在运行时我得到三个错误: Uncaught ReferenceError: exports is not defined Uncaught ReferenceError: require is not defined Uncaught Error: [$injector:modulerr]
    • 为了在浏览器中运行你的代码,你需要包括一个像 systemjs 这样的模块加载器,或者使用像 browserify 这样的东西来捆绑你的代码。
    • 我刚刚使用了 browserify,它的效果非常棒,谢谢!
    猜你喜欢
    • 1970-01-01
    • 2017-05-07
    • 2017-08-18
    • 1970-01-01
    • 2017-09-09
    • 2022-01-12
    • 2021-12-19
    • 2017-03-27
    相关资源
    最近更新 更多