I'm using Angular 2.0.1.
I have a component that can take in any other component via <ng-content>
-- this works great.
The issue I run into is when I want to reference the injected component.
If I knew that <ng-content>
would only ever be one component I could say:
@ContentChild(MyComponent) dynamicTarget: IMyComponent;
but because it could be any component (the only assumption I would make is that any injected component implements a specific interface) it become trickier.
I've also tried <ng-content #dynamicTarget'>
and then referring to it by saying @ContentChild('dynamicTarget') dynamicTarget: IMyComponent;
but this returns undefined.
Does anyone know how I could tell Angular 2 that this thing is an instance of a component so that I can attempt to call a function on it?
To further clarify the use case -- I have a multi-step wizard that could take in any component as content, and I want to call the validate
function on the content (which again, I would assume exists on said instance)