Answer the question
In order to leave comments, you need to log in
Is it always necessary to load a service in Angular2?
Hello, I have a question. I have a ngTranslate service that is responsible for languages and I loaded it in app.component in the main application component for switching. I have created another component that lies in the main component and I want to switch the language through it, so I must "inject" this service into it. But if I add it to the main component, can I give control to the child components?
Answer the question
In order to leave comments, you need to log in
The service must be specified in the component's Providers or at least one of its parent components.
I have all services connected in Providers of the main component (AppComponent).
If you add a service to the providers for each component, then the instances of the services when you insert (Inject'e) into the corresponding components will differ.
Well, something like this, of course, put your own plus / minus icons, but the code is working, even if you just click on dummies where there should be plus / minus, the number will change
jsfiddle
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question