I
I
iluxa18102019-03-14 08:11:05
Angular
iluxa1810, 2019-03-14 08:11:05

What is providedIn in the Injectable decorator?

I didn’t understand a little what kind of parameter providedIn is in Injectable and in what cases should it be used?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2019-03-15
@iluxa1810

Injectable classes can be included in the root of the application or in submodules (for lazy loading, for example). There are other ways.
For example, you include Injectable classes at the root and declare them in the providers group of the @NgModule decorator, and you end up with a sheet of a bunch of services. Or you declare providedIn: root in the @Injectable decorator itself, and you don't need to declare them in @NgModule anymore.

V
Vladimir, 2019-03-14
@Casufi

https://angular.io/guide/hierarchical-dependency-i...
https://angular.io/api/core/Injectable#providedIn
https://angular.io/guide/singleton-services

C
cpptula, 2019-03-14
@cpptula

I think the most intelligible explanation is here https://angular.io/guide/dependency-injection under Injector hierarchy and service instances

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question