【发布时间】:2017-09-30 07:38:21
【问题描述】:
我正在使用 bootbox,我需要在其中显示产品信息。产品信息以 json 形式返回,并带有 rest 调用。我正在考虑使用模板,并从 json 转换为 html。我在模板中需要 ng-repeat 等。想法是我可以调用模板并获得一个 html 结果。
但似乎 angularjs $compile 需要绑定到要渲染的元素。有什么想法吗?
【问题讨论】:
标签: angularjs angularjs-templates
我正在使用 bootbox,我需要在其中显示产品信息。产品信息以 json 形式返回,并带有 rest 调用。我正在考虑使用模板,并从 json 转换为 html。我在模板中需要 ng-repeat 等。想法是我可以调用模板并获得一个 html 结果。
但似乎 angularjs $compile 需要绑定到要渲染的元素。有什么想法吗?
【问题讨论】:
标签: angularjs angularjs-templates
我认为你可以使用 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>
【讨论】: