2016-09-21 12 views
3

: のは、私は2つのsubcomponents ArAdを持っComponent Aを持っていると仮定しましょう。 Subcomponent Arは再帰的に作成されたツリーであり、subcomponent Adは再帰的ツリー(subcomponent Ar)の選択されたノードに関する詳細を示すコンポーネントです。 @Outputを使用して、Arのサブ(サブ)コンポーネントから選択したノードをComponent Adに送信するにはどうすればよいですか?それは@Outputか他の何かであるべきですか?Angular2再帰的なコンポーネント出力

app.component.html:

<tree [input]="fooTree" [output]="updateDetails($event)"></tree> 
<tree-details [input]="input"></tree-details> 

tree.component.html:

<tree [input]="fooTree.children"></tree> 

ツリーdetails.component.html

<div>{{input.name}}</div> 
<div>{{input.id}}</div> 

この場合、ルートツリーの詳細しか表示されません。選択されたときに、他のノード(再帰的に作成されたノード)から情報を取得するにはどうしたらいいですか?

答えて

5

UPDATE

そのデモアプリで見やすい:https://plnkr.co/edit/WaYluZyPaC0OEV0YovbC?p=preview

..

あなたtree-component Arは@Ouput()を持つことができます。 AppComponentはこの出力を消費し、選択したデータを第2のサブコンポーネントdetail-componentに送信します。

app.component.html

<tree (yourOutputNameHere)="yourFunctionToReceiveAndPostSelectedData($event)"></tree> 
<details #yourDetailViewComponent></details> 

tree.component.html

<tree (yourOutputNameHere)="yourFunctionToReceiveAndPostSelectedData($event)"></tree> 

あなたtree-component@Input()を持っている可能性があり、あなたのテンプレートの内側に、あなたがこのような何かを行うことができます:

app.component.html

<tree [detail-view-input]="yourDetailViewComponent"></tree> 
<details #yourDetailViewComponent></details> 

tree.component.html tree.component.htmlと

<tree [detail-view-input]="detailViewInput"></tree> 
+0

しかし、いただきましたか!?どんな出力もありませんか? – ulou

+0

ええ、その再帰的な、心にそれを持っていない.. – mxii

+0

これは私が必要としたexatclyです。どうもありがとうございました :) – ulou