0

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

但似乎 angularjs $compile 需要绑定到要渲染的元素。任何想法?

4

1 回答 1

0

我认为您可以使用 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>
于 2017-09-30T08:33:39.050 回答