Every tutorial about DI in Angular 2 is to set the dependencies into the constructor. But what if I want to create an instance of the class and the class have some dependencies to other classes.
I have class A and B. Class B should be inject into A. But A is different every time and should be able to create a instance of it.
If I set up the DI in the constructor from A
, how to call new A()
?
I tried to add B
as private variable to A
with the @Inject(B)
decoration.
class A {
@Inject(B) b: B;
}