Created
October 5, 2016 13:28
-
-
Save cloudscape-germany/7181de60ad8f92f73cfd1889b3954a38 to your computer and use it in GitHub Desktop.
INCLUDE TEMPLATE COMPONENT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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