【问题标题】:Is there a way to get transform with template to html?有没有办法将模板转换为 html?
【发布时间】:2017-09-30 07:38:21
【问题描述】:

我正在使用 bootbox,我需要在其中显示产品信息。产品信息以 json 形式返回,并带有 rest 调用。我正在考虑使用模板,并从 json 转换为 html。我在模板中需要 ng-repeat 等。想法是我可以调用模板并获得一个 html 结果。

但似乎 angularjs $compile 需要绑定到要渲染的元素。有什么想法吗?

【问题讨论】:

    标签: angularjs angularjs-templates


    【解决方案1】:

    我认为你可以使用 ng-include:

    var app = angular.module('myApp', []);
    app.controller('productCtrl', function($scope) {
      $scope.productInfos = [];
    });

    使用 ng-include(您必须根据模板的位置调整路径)

    <div ng-app="myApp" ng-controller="productCtrl"> 
      <div ng-include="'product-information.html'"></div>
    </div>   
    

    你可以在product-information.html中做ng-repeat

    <div ng-repeat= "info in  productInfos"> {{ info.prop1 }}</div>
    

    【讨论】:

    • 谢谢。这并不理想,但我想它仍然可以接受,我很乐意尝试,但我如何获得最终的 html?因为我需要在对话框中显示它们,所以我使用的是 bootbox。所以我需要做 bootbox.alert(html)
    猜你喜欢
    • 1970-01-01
    • 2016-01-13
    • 2013-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多