我正在获取一个已编译模板的页面。问题是模板在两种情况下都是针对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;
});