Answer the question
In order to leave comments, you need to log in
What is @inject actually used for?
Clearly, a decorator allows dependencies to be injected into an existing class. These can be classes or individual primitives.
But why write @Inject if angular allows you to omit this keyword?
In what cases to use @Inject - can you give a good example of when this is apropos?
Answer the question
In order to leave comments, you need to log in
To take from the injector entities whose token is not a class constructor, but is, for example, a string or an object of type InjectionToken.
As examples - LOCAL_ID
, DOCUMENT
, MAT_DIALOG_DATA
etc.
@Inject is always present, just for class instances where the token and its type match, this decorator can be omitted.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question