An application injection context is the application-level dependency-injection scope used by standalone Angular configuration and bootstrapping. Providers belong here when configured through bootstrapApplication or application configuration. section 2.3.2
Standalone APIs such as provideRouter and provideHttpClient configure dependencies directly. When a library still exposes an NgModule, importProvidersFrom extracts its providers for use in this context, preserving interoperability. section 2.3.2
Application-level providers
In app.config.ts, define an ApplicationConfig with providers such as provideRouter(routes) and provideHttpClient(). Use importProvidersFrom(HttpClientModule) when a dependency has no suitable standalone API. section 2.3.2
Table 2.1 Different scenarios of providing dependencies
|
Question
|
Answer without standalone APIs
|
Answer with standalone APIs
|
|---|---|---|
|
Do I need to provide every dependency in every component?
|
Either this or mark the service as
providedIn:
'root'.
|
We can use a standalone API if one is provided.
|
|
How do I import services that are provided in other modules (without special standalone APIs)?
|
Import the module directly into the component.
|
Use the
importProvidersFrom function in the application main.ts file.
|
|
How do I import built-in Angular dependencies?
|
Import the whole module.
|
Use existing standalone APIs.
|
Compare dependency provision before and after standalone APIs, including when to use importProvidersFrom or existing standalone provider functions. section 2.3.2
