K
K
Konstantin2020-08-25 17:06:47
Angular
Konstantin, 2020-08-25 17:06:47

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

1 answer(s)
A
Anton Shvets, 2020-08-25
@Junart1

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_DATAetc.
@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 question

Ask a Question

731 491 924 answers to any question