I'm trying to inject a list of instances to my Angular component but since it doesn't work and I can't find any documentation on it I think it's maybe not possible. So in this case my question would be how to achieve the same effect in a clean way without handwiring anything.
In Spring for example I would have a few concrete actions that extend from an abstract Action
class or implement the Action
interface.
@Component
class MyAction1 extends Action {
...
}
@Component
class MyAction2 extends Action {
...
}
@Component
class MyConsumer {
@Autowired
List<Action> actions;
}
Since the MyAction1
and MyAction2
are loaded in the runtime, MyConsumer
will have its list filled with 2 instances. Is there any way to do this in Angular without handwiring?
EDIT: In Angular code what I want would be:
export abstract class ActionBase {
...
}
@Injectable()
export class MyAction1 extends ActionBase {
...
}
@Injectable()
export class MyAction2 extends ActionBase {
...
}
@Component(...)
export class MyConsumerComponent {
constructor(
private availableActions: ActionBase[]
) { }
}
I would expect MyConsumerComponent to have the two actions inside availableActions
when it is initialized.
Cheers