I am using Angular2/4 for few months now and I still cannot figure out what is the difference between these two methods and which one I should use about Dependency Injection
Can you help me please.
First method : via the constructor
...
constructor(
private myService: MyService
) {
// this.myService.myMethod() ...
}
...
and
Second Method : via the Injector
...
private myService: MyService;
constructor(
injector: Injector
) {
this.myService = injector.get(MyService);
// this.myService.myMethod() ...
}
...
I understand what is done in each method, bubt I cannot figure out the best practice.
I know it is probably a subjective opinion, but I think there pros and cons for both of them.
Thanks for any explanation.