Reputation: 15
I am calling ng-int() on ng-repeat like this:
<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). I am getting same size for all the 3 elements. 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
Upvotes: 1
Views: 766
Reputation: 5128
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. What I would do is save the size variable into the val object.
<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}];
Upvotes: 3