Generate HTML string from AngularJS template string

前端 未结 2 843
陌清茗
陌清茗 2021-02-20 09:00

I have angularjs template as a string including \"ng-repeat\" and other directives. I want to compile it in the controller to produce the result HTML as string.

Example

2条回答
  •  难免孤独
    2021-02-20 09:57

    Give this a whirl:

    var template = angular.element('
    {{item.data}}
    '); var linkFunction = $compile(template); var result = linkFunction($scope); $scope.$apply(); console.log(template.html());

提交回复
热议问题