Angular 2+将非模块导入TS

问题描述 投票:0回答:1

我制作了一个库,它需要支持多个应用程序。但是,其中一个站点是非角度的,将不支持“模块”,因此我无法在函数上使用“导出”。

我的外部图书馆:

var foo = (function() {

    function MyFunction(){
    }

    MyFunciton.prototype.bar(){
    }

    return MyFunction;

}());

我的问题:如何不导出将其导入我的component.ts中?

angular typescript ecmascript-6 ecmascript-5
1个回答
0
投票

angular.json部分的scripts文件中包含脚本。

  "architect": {
    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
       //...
        "scripts": [
          "src/assets/foo.js.js"
        ]
      },

在您的组件服务中,声明您的变量。然后,您可以使用它而不会抱怨打字稿。

//declare this on top of your component/service
declare let foo: any;

myMethod()
{
 var inst = new foo();
 inst.bar();//call bar
}
© www.soinside.com 2019 - 2024. All rights reserved.