Haddar Macdasi
Haddar Macdasi

Reputation: 3555

Angular 2 http service is singleton or not?

I'm using http service imported from @angular/http inside a shared module , I extend the http service using class inheritance. So my shared module has a service called "AuthHttp" which extends http service. Inside my main app module I define people providers , provide : http useClass : AuthHttp. And inside my app at different components I inject the http service , is it possible or by design that the service is not singleton ?

Upvotes: 1

Views: 1640

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657148

If you provide the service in @NgModule({providers: [...]}) of the AppModule or a module directly or indirectly imported by AppModule, then you get a singleton.

If you provide the service in a @Component(...), then you get a service instance per component instance.

Upvotes: 7

Related Questions