I'm trying to make use of treant-js in an Angular2 project, and I'm struggling with how to properly integrate it.
I have a working vanilla JavaScript / HTML example that I'm trying to make work in Angular2.
I've created a component, added treant-js and raphael from npm, and imported them into the component.
import * as Raphael from 'raphael';
import * as Treant from 'treant-js';
I've setup the html template and the corresponding css to match the standalone javascript project.
<div class="tree-wrapper" >
<div class="chart" id="test-tree"></div>
</div>
And in the class I'm defining the tree-structure variable
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 ***
}
In the JavaScript / HTML version, the tree is loaded in an inline script like this:
<script>
new Treant( tree_structure );
</script>
What's the proper way to initialize this in Angular2?
I was thinking something like this:
private tree: Treant = new Treant();
ngOnInit() {
tree ( this.tree_structure );
}
However Treant isn't a function.
I'm sure I'm missing something obvious here, but I can't wrap my head around this.