How to use string retrieved from back-end as template in Angular2?

前端 未结 2 1632
生来不讨喜
生来不讨喜 2021-01-29 10:24

In an Angular2 app, I\'d like to use ajax to retrieve a html tag string from back-end and use it as template in Angular2.

// The str I get from server by ajax i         


        
相关标签:
2条回答
  • 2021-01-29 10:36

    I think you can send this particular html as a template in a component like this

    angular.module('MenuApp')
    .component('itemset1', {
    templateUrl: '<my-hero [hero]=\"hero\"></my-hero>',
    });
    
    0 讨论(0)
  • 2021-01-29 10:43

    Instead of a template, pass the string to $compile to create a DOM element: https://docs.angularjs.org/api/ng/service/$compile

    0 讨论(0)
提交回复
热议问题