0

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?

dopatraman
  • 13,416
  • 29
  • 90
  • 154
  • The dcl-wrapper in http://stackoverflow.com/questions/36325212/angular-2-dynamic-tabs-with-user-click-chosen-components/36325468#36325468 might do what you want or work as a template for your custom solution. – Günter Zöchbauer Aug 22 '16 at 16:25
  • the dynamic component loader has been deprecated – dopatraman Aug 22 '16 at 16:50
  • I didn't change the name of the custom component when `DynamicComponentLoader` was deprecated, but it doesn't use DCL anymore in the newest examples (there are also still the older ones that use it) – Günter Zöchbauer Aug 22 '16 at 16:59

0 Answers0