导入具有构造函数的Typescript模块

用户1647160

我想将文件分成几个模块。一个模块具有一个构造函数。我可以将我的模块导入另一个文件,但是我不知道如何在新文件中调用我的构造函数。

namespace CreditReports{
  export class CreditReportVM {
        //some code

    constructor(targetElement: HTMLElement) {
        ko.applyBindings(this, targetElement);
        this.init();
     }

    public init = () => {
        //some code
     }

  }
}
利昂

您只需要导出名称空间。

export namespace CreditReports {
    //...
}

然后,当您要调用构造函数时:

import { CreditReports } from "./my-module";

//...

new CreditReports.CreditReportVM(myElement);

您应该用"./my-module"打字稿模块所在的文件名(也应该是路径)替换

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章