Discovering the any and platform provider scopes
Tree-shakable providers make it possible to create dependencies that are removed from a compiled bundle if they have not been unused. This is especially important for Angular libraries, but it also plays a role in large Angular applications and monorepositories that contain multiple Angular applications.
As an experienced Angular developer, you are probably already familiar with the root
provider scope shorthand, which can be passed to the providedIn
option in the Injectable
decorator factory, and the InjectionToken
constructor. It is used to create an application-wide singleton dependency.
Angular version 9 introduced two new provider scope shorthands, namely any
and platform
. In this section, we are going to discuss any
, which is the most complex of the two provider scope shorthands.
The any provider scope
The any provider scope declares a singleton dependency per module injector. This means that the root module –...