Angular 2 - Mix dependency injection in constructor with other arguments Angular 2 - Mix dependency injection in constructor with other arguments typescript typescript

Angular 2 - Mix dependency injection in constructor with other arguments


Dependency injection (DI) only works for classes created by DI. If you create classes with new Xxx(), there is no DI happening.

If the instance is created by DI then you can't pass your own parameters.
You would need to create providers for these parameters for DI to be able to inject them.

What you're doing is the correct way.


As far as I know it's not possible to combine ng2 dependency injection and custom arguments in the constructor.

In angular 4 you can do it. See my answer here https://stackoverflow.com/a/46813768/586609