'Problems to represent a Tree using PrimeNG
I have a question about representing a tree with PrimeNG. I would like to test the representation of the tree before filling it with data from a JSON file. So I tried the following. Firsteval I wrote the HTML file, where my tree shoud be represented. Thats shown in the following code.
<h1>Test</h1>
<p-tree [value]="files" selectionMode="single" layout="horizontal"></p-tree>
After that, I did the following in the component. I wrote a method where the TreeNode-Array files
is filled with some short Input data. After that, I assigned files to the value of this function. This is shown in the following code:
files: TreeNode[] = this.bla();
bla(): TreeNode[]{
let TN1: TreeNode = {};
let TN2: TreeNode = {};
let TN3: TreeNode = {};
let TN4: TreeNode = {};
console.log('in bla');
TN1.data='TN1';
TN1.label='TN1';
TN2.data='TN2';
TN2.label='TN2';
TN3.data='TN3';
TN3.label='TN3';
TN4.data='TN4';
TN4.label='TN4';
TN1.children = [TN3];
TN2.children = [TN4];
return [TN1,TN2,TN3,TN4];
}
In my opinion, that's all I should do for testing. I got no Errors or something like that, but the tree is not shown... I hope that anyone can help me.
Thank you!
Solution 1:[1]
Same issue, I just add the TreeModule into the file *.module.ts. Import and added to NgModule
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mlnzc |