I am trying to build tree structure using angular 2 with a basic parent-child concept.
component.html template looks like below:
<li class="nav-item " *ngFor="let dir of directories">
<a href="javascript:;" class="nav-link nav-toggle">
<i class="fa fa-clock-o"></i>
<span class="title">{{ dir.name }}</span>
<span class="arrow"></span>
</a>
<ul class="sub-menu" *ngFor="let file of directories.child">
<li class="nav-item ">
<a href="#" class="nav-link ">
<span class="title">{{file.name}}</span>
</a>
</li>
<navigation-bar [directories]="dir.child"></navigation-bar>
</ul>
</li>
component.ts file :
import { Component, Input } from '@angular/core';
@Component({
selector: 'navigation-bar',
templateUrl: './app/home/navigationBar.component.html',
})
export class NavigationBarComponent {
@Input() directories: Array<Tree>;
}
export class Tree{
directories: any;
constructor()
{
this.directories = [
{
name: 'parent1',
child: [{
name: 'child1',
child: []
},
{
name: 'child2',
child: []
}]
},
{
name: 'parent2',
child: {
name: 'child1',
child: []
}
},
{
name: 'parent2',
child: [{
name: 'child1',
child: []
},
{
name: 'child2',
child: []
}]
}];
}
}
But it always renders the parent nodes only.
Don't know where I am doing wrong! I am almost blank now. Any suggestion, please...