我正尝试在Angular2项目中使用treant-js,并且我正在努力如何正确整合它。在Angular2项目中集成Treant-js项目
我有一个可用的香草JavaScript/HTML示例,我正尝试在Angular2中进行工作。
我创建了一个组件,从npm添加了treant-js和raphael,并将它们导入到组件中。
import * as Raphael from 'raphael';
import * as Treant from 'treant-js';
我已经设置了html模板和相应的CSS来匹配独立的javascript项目。
<div class="tree-wrapper" >
<div class="chart" id="test-tree"></div>
</div>
而且在班上,我定义了树结构变量
private tree_structure: any = {
chart: {
container: "#test-tree",
levelSeparation: 20,
siblingSeparation: 15,
subTeeSeparation: 15,
rootOrientation: "WEST",
node: {
HTMLclass: "tree-wrapper",
drawLineThrough: true
},
connectors: {
type: "straight",
style: {
"stroke-width": 2,
"stroke": "#ccc"
}
}
},
nodeStructure: {
text: {
name: { val: "Djokovic, Novak", href: "http://... }
},
HTMLclass: "animal",
image: "flags/can.jpg",
children: [...
*** the rest of the object graph continues ***
}
在JavaScript/HTML版本,树被加载内嵌脚本是这样的:
<script>
new Treant(tree_structure);
</script>
在Angular2中初始化它的正确方法是什么?
我的想法是这样的:
private tree: Treant = new Treant();
ngOnInit() {
tree (this.tree_structure);
}
然而树精是不是一个函数。
我敢肯定我在这里错过了一些明显的东西,但是我无法将这个包裹在头上。
这不适用于我在IE 11中。有了这些设置,我得到它的铬和Firefox的工作,但IE说: 'SCRIPT5009:'模块'是未定义的' –
这可能是一个问题与您的模块加载器配置。 –