Service Tokens
Service tokens are unique identifiers what provides type-safe access to a value stored in a Container
.
Injecting service tokens
They can be used with the @Inject()
decorator to overwrite the inferred type of the property or argument.
Tokens with same name
Two token with the same name are different tokens. The name is only used to help the developer identify the tokens during debugging and development. (It's included in error the messages.)
Difference between Token and string identifier
They both achieve the same goal, however, it's recommended to use Tokens
as they are type-safe and cannot be mistyped, while a mistyped string identifier will silently return undefined
as value by default.
Last updated