It doesn't need to be app-wide. If you add a service class to providers of a component only this component and its descendants share an instance. (Don't add it to the providers of the descendants, otherwise they get their own instance instead of a shared one.
On Tuesday, February 23, 2016 at 5:58:43 AM UTC+1, Chris Derossi wrote: > > I had a similar need and wound up having to address it in a very > roundabout way. Here's the thread: > https://groups.google.com/forum/#!topic/angular/KbZS207xL-k > > In short, I created an external app-wide service that the components used > to find each other. This is the equivalent of having to use global > variables, in my opinion, and unfortunate that this is necessary. > > Since a component can have only a single <router-outlet>, it seems a big > omission that that component can't ask the router which component instance > is currently occupying that placeholder slot. > > > On Monday, February 22, 2016 at 6:39:16 PM UTC-8, JG wrote: >> >> Here <http://plnkr.co/edit/71hmAy2hW3Jh2Vg2XsI6> ( >> http://plnkr.co/edit/71hmAy2hW3Jh2Vg2XsI6) is a Plunker that >> demonstrates what I am talking about. >> >> Look at the src/app.ts file, lines 28 - 30. This code (line 29) does not >> execute. >> >> >> On Monday, February 22, 2016 at 6:01:14 PM UTC-5, Long Field wrote: >>> >>> Not sure what you did, show us your code >>> >>> On Tuesday, February 23, 2016 at 7:50:50 AM UTC+11, JG wrote: >>>> >>>> I have a parent Component that has a template with " >>>> <router-outlet></router-outlet>" in it. It also has a @RouteConfig >>>> annotation that specifies which sub component is associated with different >>>> routs. >>>> What I am trying to do is: to subscribe to Events (EventEmitter) that >>>> are fired by the loaded sub component. >>>> >>>> I can easily inject the sub component into my parent component and >>>> subscribe to it's EventEmitter, but that doesn't work. I think that the >>>> problem is that the injected instance is not the same the one that emits >>>> the events. >>>> >>>> So, my question is: if a component has @RouteConfig([ {path: >>>> "/somePath", component: ChildComponent, as: "ChildCmp"}]), how can I >>>> get a reference to ChildComponent to subscribe to it's event? >>>> >>> -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
