我刚开始学习typescript。我被要求用JSweet转换一个java库,以便将其嵌入到一个Angular项目中。java库只包含纯逻辑,不依赖于其他库。转换过程很顺利,结果是一系列.ts文件,格式如下:
namespace com.test {
export lib_class_name {
... transplied content ...
}
}当我试图从一个angular组件引用这些类时,问题就出现了。示例:
import { Component, OnInit } from "@angular/core";
@Component({
selector: "app-dashboard",
templateUrl: "./dashboard.component.html",
})
export class DashboardComponent implements OnInit {
constructor() {
let tmp = new com.test.lib_class_name()
}
ngOnInit() {}
}代码编译正确,但我收到一个运行时错误:
ERROR Error: Uncaught (in promise): ReferenceError: com is not defined
ReferenceError: com is not defined
at new DashboardComponent (dashboard.component.ts:10)基于我在互联网上找到的类似的错误解决技巧,我尝试了几种方法来引用这个类,但结果总是相同的。
为什么会发生这种情况?我如何解决它?
谢谢
发布于 2021-04-02 07:13:25
我解决了这个问题:我需要在JSweet transplier选项中启用模块支持。现在,JSweet在表单中生成类:
import {x} from '..\x'
...
export class y {
}它们与angular模块兼容。
https://stackoverflow.com/questions/66888515
复制相似问题