angularjs从指令访问数组对象

angularjs从指令访问数组对象,angularjs,Angularjs,我只是试图构建一个已经可以访问现有json数据数组的指令。表显示了,但有人能告诉我如何才能使数据仍显示在表中。不确定如何访问它 var myApp=angular.module('myApp',[]); myApp.controller('countryController',['$scope',函数($scope){ var国家=[{ “代码”:“广告”, “名称”:“安道尔”, “人口”:“84000” }, { “代码”:“AE”, “名称”:“阿拉伯联合酋长国”, “人口”:“4975

我只是试图构建一个已经可以访问现有json数据数组的指令。表显示了,但有人能告诉我如何才能使数据仍显示在表中。不确定如何访问它

var myApp=angular.module('myApp',[]);
myApp.controller('countryController',['$scope',函数($scope){
var国家=[{
“代码”:“广告”,
“名称”:“安道尔”,
“人口”:“84000”
}, {
“代码”:“AE”,
“名称”:“阿拉伯联合酋长国”,
“人口”:“4975593”
}, {
“代码”:“AF”,
“姓名”:“阿富汗”,
“人口”:“29121286”
}, {
“代码”:“AG”,
“名称”:“安提瓜和巴布达”,
“人口”:“86754”
}, {
“代码”:“AI”,
“名称”:“安圭拉”,
“人口”:“13254”
}, {
“代码”:“AL”,
“姓名”:“阿尔巴尼亚”,
“人口”:“2986952”
}
]
$scope.countries=国家;
控制台日志(国家);
}
]);
myApp.directive('countryLoop',function(){
返回{
限制:'E',
范围:{
代码:“@”,
名称:“@”,
人口:“@”
//国家:“&”
},
模板:“CountryCodePopulation{{country.name}{{country.code}}{{country.population}”,
链接:功能($scope,element){
}
};
});

国家
代码
人口
{{country.name}
{{country.code}
{{国家人口}


您需要将其与父项绑定:

scope: {
  code: '@',
  name: '@',
  population:'@'
  countries:'=' // which is equals to "countries:'=countries'"
}
然后,在使用指令时,需要指定集合字段:

<country-loop countries="countries"></country-loop>
将从“数据”属性中获取数据,并在指令范围内为其分配“国家”字段

<country-loop data="countries"></country-loop>


我是否仍然使用restrict:'E'got it.。它不在控制器中
<country-loop data="countries"></country-loop>