我正嘗試在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:'模塊'是未定義的' –
這可能是一個問題與您的模塊加載器配置。 –