我制作了一个库,它需要支持多个应用程序。但是,其中一个站点是非角度的,将不支持“模块”,因此我无法在函数上使用“导出”。
我的外部图书馆:
var foo = (function() {
function MyFunction(){
}
MyFunciton.prototype.bar(){
}
return MyFunction;
}());
我的问题:如何不导出将其导入我的component.ts中?
在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
}