I'm trying to pass a component to be rendered within another component:
// dynamic-component.ts
export class DynamicComponent {
@Input() content : ObservableContent;
this.render(component) {
this.componentResolver.resolveComponent(component).then(factory => {
let cmp = this.viewContainerRef.createComponent(factory, this.viewContainerRef.length, null, null);
// render code
})
}
ngOnChanges(changes) {
this.render(changes.content.currentValue);
}
}
What this does is take an input, content
which is meant to be a reference to an instantiated component:
<dynamic-component [content]="dynamicComponent"></dynamic-component>
// code:
export class ComponentWhereDynamicIsLoaded {
...
this.dynamicComponent = new TestComponent();
}
When the parent component is loaded, dynamicComponent
is rendered as the string [object] [Object]
, which makes sense, since im sure Angular parses the object returned by the TestComponent
constructor as a string. The question is, how do I properly pass the TestComponent
into the DynamicComponent
?