#Why is HttpClient service not declared in Providers array as other services ?

5 messages · Page 1 of 1 (latest)

worthy stratus
#

We know most services are declared in the providers array but why is it not the case with HttpClient service ?

cedar breach
#

You include the HttpClientModule

worthy stratus
cedar breach
#

HttpClientModule does the setup for you

proven shell
#

@worthy stratus most services are meant to be singletons (one instance in the whole application). There are provided with the Injectable metadata:

@Injectable({
  providedIn: 'root'
})

By doing so, you don't need to declare services in the providers array. If you are still using the providers array, either you are on an ancient version of Angular or with practices based on a old documentation/blog post.