Angularjs:使用循环

时间:2016-09-08 04:11:33

标签: javascript angularjs

我正在获取一个已编译模板的页面。问题是模板在两种情况下都是针对alldata [1]的循环编译的。

var app = angular.module("bcreport", []);

app.controller("bcreport_controller", function($scope, $compile) {
  var alldata = [{'name':'tom','age':34},{'name':'alice','age':24}];

  for (var i=0; i<alldata.length; i++)
  {
    $scope.name = alldata[i]['name'];
    $scope.age = alldata[i]['age'];

    angular.element(document.querySelector("#container")).append($compile("<bcr></bcr>")($scope));
  }
});

app.directive("bcr", function () {

   var directiveDefinitionObject = {
     restrict:'E',
     transclude:true,
     scope:true,
     templateUrl: "templates/report_template.html",
     replace:true,
   };

   return directiveDefinitionObject;

});

0 个答案:

没有答案
相关问题