The semantics of @Injectable(providedIn: 'root')? The semantics of @Injectable(providedIn: 'root')? typescript typescript

The semantics of @Injectable(providedIn: 'root')?


When you write @Injectable(providedIn: 'root') this means that the service in singletion for whole application and you can inject in anywhere in the application.

When you want to make service singleton only for an exact module, you need to assign your module as the parameter to the providedIn - @Injectable(providedIn: MyModule)

The only other action required in order to use the @Injectable decorated service is to import it and constructor inject it and that's it. No need to import it in the AppModule.