Angular2 recursive component output

By : ulou
Source: Stackoverflow.com
Question!

I have following problem: let's assume that I have Component A that have two subcomponents Ar and Ad. Subcomponent Ar is recursive created tree and subcomponent Ad is component which shows details about choosen node in recursive tree (subcomponent Ar). How can I send selected node from sub(sub)component in Ar to Component Ad using @Output? Should it be @Output or something else?

app.component.html:

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

tree.component.html:

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

tree-details.component.html

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

In this case I will see only root tree details, how can I do this to get info from other node (one of recursivly created), when is selected?

By : ulou


Answers

UPDATE:

Its easier to see in a demo-app: https://plnkr.co/edit/WaYluZyPaC0OEV0YovbC?p=preview

..

Your tree-component Ar could have an @Ouput(). Your AppComponent would consume this output and would post the selected data to the second sub-component detail-component.

app.component.html

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

tree.component.html

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

Your tree-component could even have an @Input() and inside of your template you could do something like this:

app.component.html

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

tree.component.html

<tree [detail-view-input]="detailViewInput"></tree>
By : mxii


Start by grouping the entries by OrderCustomerID, and constructing an array from each group. After that, add groups to a dictionary:

var byCustId = OrderProductsOrder
    .GroupBy(p => p.OrderCustomerID)
    .ToDictionary(g => g.Key, g => g.ToArray());

Now you can grab individual arrays with TryGetValue or operator []:

OrderProduct[] customer2Order;
if (byCustId.TryGetValue(2, out customer2Order) {
    ... // Use customer2Order array
}


You can acheive this on your own TextView class that extends the Android TextView class and override the onTouchEvent(MotionEvent event)

You can then modify the instances text color based on the MotionEvent passed.

For example:

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
       // Change color
    } else if (event.getAction() == MotionEvent.ACTION_UP) {
       // Change it back
    }
    return super.onTouchEvent(event);
}


This video can help you solving your question :)
By: admin