0

How to send data between tow components in Angular 2 application considering: - two components in two different routes ( thus, the only shared component is the root one)

I have managed to: - Use Shared services or Singleton however, how can I trigger the event from the first component to another ( that lies in the another routes )

I have managed to trigger the event using output to the last component before the root ( but not accross the root-app component)

Any help, links, clues appreciated!

<div class="wrapper">
   <div class="tasks-list">
    <router-outlet></router-outlet>
  </div>
<div  class="details">
    <task-details></task-details>
  </div>
</div>

this is app.component.html

I have a list of 'task.component' when clicking on of the itmes it should open in the 'task.details.component'. I hop I illustrated the idea in a good way.

Cœur
  • 37,241
  • 25
  • 195
  • 267
ßastian
  • 1,814
  • 3
  • 13
  • 22

2 Answers2

0

Please go through this:

https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service

A parent component and its children share a service whose interface enables bi-directional communication within the family.

The scope of the service instance is the parent component and its children. Components outside this component subtree have no access to the service or their communications.

srikanth_k
  • 2,807
  • 3
  • 16
  • 18
-1

Use the $rootScope. Create there variable, which will be visible from anywhere.