angular - Angular 2+将非模块导入TS
问题描述
我制作了一个库,它需要支持多个应用程序。然而,其中一个站点是非角的,不支持“模块”,因此我无法在我的函数上使用“导出”。
我的外部图书馆:
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
}
推荐阅读
- api - 导出函数 dart 之外的数据
- vuejs2 - 无法读取未定义的 VueJS Firebase 的属性“forEach”
- visual-studio - 请识别此 Visual Studio 标志
- google-cloud-platform - 在 GCP Composer 中增加单个节点的内存
- javascript - 模仿 [colA] 和 [colB] 之间的 [condition] 续集
- azure - 从 Cosmos DB 获取详细信息的更快查询
- ios - PDFDocument中的变音符号不敏感搜索
- interface - 使用接口导出函数 - F#
- java - 无法删除或更新父行外键约束失败 JPA Spring Boot
- typescript - TypeScript:获取联合可能类型的名称(作为字符串)?