Dynamically load HTML template in angular2

后端 未结 5 1528
余生分开走
余生分开走 2020-11-28 06:54

I have created a project using angular-cli which contains AppComponent as follows:

import { Component } from \'@angular/core\';         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 06:57

    You could use [innerHtml] in a my-template component with something like this (I didn't test) :

    @Component({
        selector: 'my-template',
        template: `
    
    `}) export public class MyTemplate { private myTemplate: any = ""; @Input() url: string; constructor(http: Http) { http.get("/path-to-your-jsp").map((html:any) => this.myTemplate = html); } }

提交回复
热议问题