Skip to content

Angular Template, Inject HTML from external resource #53

Description

@Pritraj
        <div #container name="container"></div>
@ViewChild('container', { static: true, read: ViewContainerRef }) container: ViewContainerRef;
  pageVars = { infoVisible: null, template:"" }

constructor(private compiler: Compiler){}

this.createComponent(this.container,this.pageVars);

createComponent(where,data){
    let tempComponentClass = class TempComponentClass { pageVars = data;}
    const tempComponent = Component({template: data.template})(tempComponentClass);
    const tempNgModule = NgModule({imports: [ CommonModule ], declarations: [tempComponent]})(tempComponentClass);

    const module: ModuleWithComponentFactories<any> = this.compiler.compileModuleAndAllComponentsSync(tempNgModule);
    where.createComponent(module.componentFactories.find(f => f.componentType === tempComponent));
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions