Dynamically load HTML template in angular2

后端 未结 5 1504
余生分开走
余生分开走 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 07:17

    It appears that the way to do this now is to set the responseType when you make your request. HttpClient-Requesting non-JSON data `

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

    `

提交回复
热议问题