实例化并将Angular组件的新实例添加到页面

时间:2019-01-01 23:49:29

标签: angular components factory ngx-bootstrap-accordion

我有以下方法尝试添加新的手风琴实例。有没有一种方法可以直接动态地创建组件,而不必创建新的“ MyAccordionComponent”类型的类文件并导入?

buildAccordion(){
       let accConfig = new AccordionConfig();
        let accordionComponent = new AccordionComponent(accConfig);
        accordionComponent['class'] = 'accord';
        let accordionPanelComponent = new AccordionPanelComponent(accordionComponent);
        accordionPanelComponent.heading = "data_name";
        accordionPanelComponent.panelClass = "panel_10";
        accordionComponent.addGroup(accordionPanelComponent);

        const componentRef = this.componentFactoryResolver.resolveComponentFactory(accordionComponent);  // error occurs here!!     
        this.viewContainerRef.createComponent(componentRef);
    }

0 个答案:

没有答案