0

I'm trying to create components dynamically. The simplified code which creates the component looks like this -

loadDynamicComponent(container: ViewContainerRef, template, data: any, settings?: any) {
    const cfr = AppInjector.get(ComponentFactoryResolver);
    const factory = cfr.resolveComponentFactory(template);
    this.componentRef = container.createComponent(factory);


    if (this.componentRef was created before) {
    ...
    }
    else
    {
        //container.clear();
        container.insert(this.componentRef.hostView);
        this.setComponentData(data, settings);
    }
}

This works well, but now I want to know if such a component has been created already before. Unfortunately, I cannot find any appropriate functions in ViewContainerRef. Is there any way to get an array that contains all created componentRef?

Lars
  • 920
  • 1
  • 14
  • 34

0 Answers0