2017-10-17 91 views
0

我想显示另一个组件的内容。 这是我menu.component.html,我想在app.component.html显示:如何在另一个组件中显示组件的内容?

<div class="Tree"> 
<tree-root [nodes]="nodes"> 
<ng-template #treeNodeTemplate let-node let-index="index"> 
<a><span>{{ node.data.description }}</span></a> 
</ng-template> 
</tree-root> 
</div> 

我使用angular-tree-component显示在树表单数据。

这是我app.component.html这里我使用的是<menu>选择该菜单组件的显示菜单:

<menu [path]="path"></menu> 

的问题是,我只得到了树的第一个元素,而不是获取数据以树形式。

+0

你肯定'nodes'正确初始化组件之间传输数据? – gsamaras

+0

@gsamaras是的,我相信 – eli

+0

@gsamaras的更多信息,看看这个问题:https://stackoverflow.com/questions/46785288/cant-show-the-contents-of-a-component-in-another-组件 – eli

回答

0

为什么不使用事件发射

//Home component.ts 
import { Events } from 'ionic-angular'; 
constructor(public events: Events) { 
    directioChange(user) { 
      this.events.publish('directiochanged', 'true'); 
    } 
} 


//AngularTreeComponent 
constructor(public events: Events) { 
     events.subscribe('directiochanged', (direction) => { 
      //Do your Tree view display Action in this receiver 
     }); 
} 
+0

'angular-tree-component'是一个npm包,它接收一些数据并以树形式显示它,我不知道它是如何实现的,我正是在使用它,因为我不想实现这个功能由我自己。 – eli

相关问题