![](/img/trans.png)
[英]Display component's content from @ContentChildren in multiple rows using *ngFor on Angular 2
[英]How to get a child component's contentchildren in Angular 2?
我在Angular 2中遇到問題。我有一個顯示菜單的主要組件。 該組件有一個名為Tabs的子級。 在此組件中,當單擊“主要”組件中的菜單項時,會動態添加Tab選項卡。 我在Tabs組件中使用@ContentChildren來獲取所有Tab組件,並且工作正常。 但是,要使其正常工作,我需要將這些contentchildren進一步傳遞到Main組件中。 我該怎么做? 我試過發射,但似乎不起作用。
@ContentChildren(TabComponent) tabs: QueryList<TabComponent>;
@Output() public tabsArrayStart = new EventEmitter();
this.tabsArrayStart.emit(this.tabs);
@Output()
僅允許從父級傳遞
(tabsArrayStart)="doSomething($event)
我建議您改用共享服務。
有關更多詳細信息,請參見https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.