If only a component should know about it's subordinates just add the providers to this components @Component(providers: ...) or @View(providers:...). This should work well. What seems not to be supported currently is to do this with service classes http://stackoverflow.com/a/34581696/217408
On Tuesday, January 5, 2016 at 1:22:02 PM UTC+1, [email protected] wrote: > > Hi, > > thanks for your fast reply. What i want to reach is, that only a specific > Component knows about its subordinates and not the entire app. Your > proposal, i think, would share the Injectables with the whole app and not > only with the AppInitializerComponent. > > Am Dienstag, 5. Januar 2016 11:26:09 UTC+1 schrieb Günter Zöchbauer: >> >> You can pass provides to the `bootstrap(AppComponent, [provider1, >> provider2])` function. >> See also >> https://angular.io/docs/ts/latest/guide/hierarchical-dependency-injection.html >> >> On Tuesday, January 5, 2016 at 10:59:23 AM UTC+1, [email protected] >> wrote: >>> >>> Hi, >>> >>> i'm a little bit confused about angular's behaviour on dependency >>> injection and providers. But first i want to give you a short overview: >>> >>> I'm new to Angular 2 and started just a few days ago with the Angular 2 >>> tutorial. I also read a lot of docs in the meantime. >>> I want to create an app which gets initialized by an initializer >>> component. So i created the main AppComponent, the AppInitializerComponent >>> and a SettingsService, which should later provide general settings, e.g. >>> the title of the site. >>> Now i tried to inject the Components / Services into their respective >>> superordinate. What i would expect is, that the AppComponent knows about >>> the AppInitializerComponent but not about the SettingsService, because it >>> is only important for the AppInitializerComponent. But i can't get it >>> working in a way like that. >>> >>> I ended up injecting both, the AppInitializerComponent and the >>> SettingsService, into the AppComponent, but it doesn't feel good to me. >>> >>> You can take a look at my current working state here: >>> https://plnkr.co/edit/ppEZRo2kharj8dJyBH6z >>> >>> I also made a plunker of my expected behaviour: >>> https://plnkr.co/edit/4C7kburx8dxfn0locFYK >>> >>> What i would expect is, that i define the AppInitializerComponent as a >>> @Component and give it a "providers" metadata attribute which contains the >>> SettingsService. The code i would expect results in an error message saying >>> that there is no provider defined for AppComponent -> >>> AppInitializerComponent -> SettingsService. >>> >>> >>> Is there any possibility in getting my expectation to work? >>> >>> Thanks a lot in advance :) >>> >>> Julian >>> >> -- 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.
