Context - I\'m trying to create a custom dropdown that can contain a number of components. I could accomplish this via the
tag, but my team is st
You can use the new .createComponent()
function.
import {ComponentRef, Injectable, Component, Injector, ViewContainerRef, ViewChild,ComponentResolver, DynamicComponentLoader} from '@angular/core';
export class InjectComponent {
@ViewChild('toreplace', {read: ViewContainerRef}) toreplace;
constructor(private dcl: DynamicComponentLoader, injector: Injector,private resolver: ComponentResolver) {}
...
this.resolver.resolveComponent((this.createWrapper()).then((factory:ComponentFactory) => {
this.cmpRef = this.theBody.createComponent(factory)
});
and remove providers: [DynamicComponentLoader, Injector]
Here's an example plunker that uses DynamicComponentLoader (in app.component.ts): https://plnkr.co/edit/azoGdAUvDvCwJ3RsPXD6?p=preview