Skip to content

Instantly share code, notes, and snippets.

@cloudscape-germany
Created October 5, 2016 13:28
Show Gist options
  • Select an option

  • Save cloudscape-germany/7181de60ad8f92f73cfd1889b3954a38 to your computer and use it in GitHub Desktop.

Select an option

Save cloudscape-germany/7181de60ad8f92f73cfd1889b3954a38 to your computer and use it in GitHub Desktop.
INCLUDE TEMPLATE COMPONENT
import { Component, Input, ViewContainerRef, OnInit, ComponentFactoryResolver, ViewChild } from "@angular/core";
import { LoggerService } from "../logger/logger.service";
@Component({
selector: "include-template",
template: "<div #includeContent></div>"
})
export class IncludeTemplateComponent implements OnInit {
@Input("src")
private templateUrl: string;
@ViewChild("includeContent", { read: ViewContainerRef })
protected contentTarget: ViewContainerRef;
constructor(private componentFactoryResolver: ComponentFactoryResolver, private log: LoggerService) {}
ngOnInit() {
var dynamicComponent = this.createContentComponent(this.templateUrl);
let componentFactory = this.componentFactoryResolver.resolveComponentFactory(dynamicComponent);
this.contentTarget.createComponent(componentFactory);
}
private createContentComponent(templateUrl) {
@Component({
selector: "include-content",
templateUrl: templateUrl
})
class IncludeContent {}
return IncludeContent ;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment