Where you add the service defines the scope of the service.
`bootstrap(AppComponent, [SomeProviders])` makes them shared globally.
@Component({
 ...
 providers: [SomeProviders],
...
})
export class SomeComponent {}

make them shared between SomeComponent and all descendant components and 
directives, this also shadows the same provider listed on ancestors or 
bootstrap.

On Thursday, March 31, 2016 at 9:26:44 AM UTC+2, Christophe HOARAU wrote:
>
> Hello,
>
> I'm still quite new to angular2, and I have a question about DI injection 
> on components.
> Component has a providers attribute in order to allow DI of services, but 
> I have seen most of the time this is not used at all and the Services are 
> injected in the boostrap. I would like to understand why, and what is the 
> difference?
>
> Let's say I have 2 "standalone" components that requires the same service. 
> If I set the providers attribute will this create 2 services ?
>
> Thanks.
>

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

Reply via email to