Angular2 recursive component output

By : ulou

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?


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


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



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



Its easier to see in a demo-app:


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.


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


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

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


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


<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:

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