2017-10-17 99 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

相關問題