We're a place where coders share, stay up-to-date and grow their careers.
Hi Daniel! I don't understand. Why would you want to inject services this way when they can be provided in Root and initialised in the constructor?
@Hi AlleAmiDev sorry, but maybe I wasn't enough clear about it.
You are right, using @Inject() it's not a desired way to inject services into your components, but that was just an example.
@Inject()
You should use @Inject('value') when you need to inject just a specific value and not a whole instance.
@Inject('value')
For ex:
providers: [ { provide: "language", useValue: "en" } ],
and then in your components:
... @Inject("language") private language, ....
Did I answer your question? :-)
Hi Daniel! I don't understand. Why would you want to inject services this way when they can be provided in Root and initialised in the constructor?
@Hi AlleAmiDev sorry, but maybe I wasn't enough clear about it.
You are right, using
@Inject()
it's not a desired way to inject services into your components, but that was just an example.You should use
@Inject('value')
when you need to inject just a specific value and not a whole instance.For ex:
and then in your components:
Did I answer your question? :-)