I am currently working with Angular 2.0.1.
One of my components can accept any other component using <ng-content>
, and this functionality is working well.
However, I face a challenge when trying to reference the injected component.
If I knew that only one component would ever be passed through <ng-content>
, I could simply declare:
@ContentChild(MyComponent) dynamicTarget: IMyComponent;
. But since it could be any component (with the assumption that each injected component implements a specific interface), things get more complicated.
I also attempted using
<ng-content #dynamicTarget'>
and then referencing it like so:
@ContentChild('dynamicTarget') dynamicTarget: IMyComponent;
, but unfortunately, this returns undefined.
Does anyone have a solution on how I could inform Angular 2 that this element is an instance of a component so that I can proceed to call a function on it?
To provide more context to the scenario - I am developing a multi-step wizard that may contain various components as content, and my objective is to execute the validate
function on the content (assuming such a function exists within the respective instances).