如何使用ng-repeat显示templateUrl? 大家好我尝试了一些方法,以显示模板的所有元素.Urlby使用ng-repeat butunfortunatelly我没有弄清楚!有谁可以帮我这个?..这是代码。
<div ng-app="myApp" ng-cloak ng-controller="Controller">
<div ><my-customer info="vaggelis"></my-customer></div>
<hr>
<div ><my-customer info="aggelos"></my-customer></div>
</div>
<script>
var app = angular.module("myApp",[])
.controller("Controller",["$scope", function($scope){
$scope.vaggelis = {
name : "Vaggelis",
surname : "Kolimitras",
age : 24
};
$scope.aggelos = {
name : "Aggelos",
surname : "Kolimitras",
age : 21
};
}])
.directive("myCustomer", function(){
return{
restrict : "E",
scope :{
customerInfo : "=info"
},
templateUrl : "my-customer.html"
};
});
</script>
这是my-customer.html文件
{{"Hi " + customerInfo.name + " " + customerInfo.surname + " with the age of " + customerInfo.age}}
答案 0 :(得分:0)
$scope.data = {
vaggelis = {
name : "Vaggelis",
surname : "Kolimitras",
age : 24
},
aggelos = {
name : "Aggelos",
surname : "Kolimitras",
age : 21
}};
<div ng-app="myApp" ng-cloak ng-controller="Controller">
<my-customer ng-repeat="cInfo in data" info="cInfo"></my-customer>
</div>
希望对你有所帮助