Revisiting the root provider scope
So far, we have discussed the following services in the Angular Academy application using the root scope provider:
SchoolsService
: Retrieve information about the available schools.CourseService
: Retrieve information about the course.ThemeService
: Set and retrieve information about the current theme.
These services have served us well as singletons in the app so far – and marking the services for use with providedIn: 'root'
via the Injectable
decorator makes it pretty easy to use them for the standard use case. If you have been around since the early days of Angular, then you might have been accustomed to injecting services as dependencies in each specific module – for example, you might have been wondering why SchoolsService
is not listed in the providers array from the schools module here:
@NgModule({ declarations: [SchoolsComponent], imports: [CommonModule, GoogleMapsModule...