0

i get several json array and i want to retrieve some data in a loop. what i want is the value of the key count

Here is my code :

                .then(function(){
                    var tabuser = JSON.parse(localStorage.getItem("myid"));

                    for(i = 0; i < tabuser.length; i++){
                        console.log(tabuser[i].id);
                        displayfilter
                            .user(token,tabuser[i].id)
                            .then(function(data){

                                console.log(data);
                                $scope.numtickets = data;


                            })
                    }

                })

Here what i get from my `console.log(data):

enter image description here

And i want to retrieve the value of the key countfor every json array. How can i display that in my view ?

1 Answer 1

1

Create a json array:

$scope.numtickets = [];

Keep pushing the value of the keycount:

$scope.numtickets.push(data);

Display the array on the view:

<div ng-repeat="numticket in numtickets">
   {{numticket.count}}
</div>
Sign up to request clarification or add additional context in comments.

5 Comments

This is a really good start but it only display the value 'count' of the last array and not every array. I think i have to push the value of 'count' in a new array and then retrieve them easily. Because your method give me several different tab which contain the key 'count' if you see what i mean.
Try using: $scope.numtickets.push(angular.copy(data))
it copy only the last value so it's the same result as before :(
Try this: .then(function(){ var tabuser = JSON.parse(localStorage.getItem("myid")); $q.all($scope.tabuser.map(function(obj) { return displayfilter.user(token,obj.id) })).then(function(data){ console.log(data); $scope.numtickets = data; }); });
i manage it, what i did is just to declare '$scope.numtickets = [];' outside the loop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.