[英]angular js calling ng-init on ng-repeat
I am calling ng-int() on ng-repeat like this: 我在ng-repeat上调用ng-int(),如下所示:
<ul class="title_page1" style="margin:0; padding:0;">
<li ng-init='some(val.id);' ng-repeat="(key,val) in menu">{{val.name}}</span><span>{{size}}</span></li>
</ul>
I have three elements in menu, by this ng-init is getting called for each ng-repeat but {{size}} from some(val.id). 我在菜单中有三个元素,通过这个ng-init被调用每个ng-repeat,但是来自某些(val.id)的{{size}}。 I am getting same size for all the 3 elements.
所有3个元素的大小相同。 Please kelp me in sorting out this.
请帮我解决这个问题。
$scope.some={function(id){
return $http({
url : 'url+id',
method : 'GET',
async : false,
}).success(function(data) {
$scope.size = data.length;
});
};
$scope.menu=[{java,php,micro}];
And this the thins I am doing but the size i am getting for all the elements is same. 这就是我正在做的事情,但我得到的所有元素的大小是相同的。 but i have seen in the google but i did not get any result from google
但我在谷歌看到,但我没有从谷歌得到任何结果
You are retrieving the data for 3 id's, however your saving them in the scope where your controller resides, which can only have one size
variable. 您正在检索3个ID的数据,但是您将它们保存在控制器所在的范围内,该范围只能有一个
size
变量。 What I would do is save the size variable into the val object. 我要做的是将size变量保存到val对象中。
<ul class="title_page1" style="margin:0; padding:0;">
<li ng-init='some(val);' ng-repeat="(key,val) in menu">{{val.name}}</span><span>{{val.size}}</span></li>
</ul>
$scope.some={function(val){
return $http({
url : 'url'+val.id,
method : 'GET',
async : false,
}).success(function(data) {
val.size = data.length;
});
};
$scope.menu=[{java,php,micro}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.