javascript - ngResource collection return -


how single result array $scope.trailers. when try access first index $scope.trailers[0] undefined. using ngresource api call

        function gettrailers(pageno){             pageno = typeof pageno !== 'undefined' ? pageno : 1;             $scope.trailers = apiservice.gettrailers().query({page: pageno});              vm.trailer = $scope.trailers[0];         }; 

$scope.trailers structure: http://imgur.com/sld4tuo

i figured out not working because of async. how make promise on query gettrailers function?

accessing 1st result in array $scope.trailers[0] , have check if either array filled or array associated array.

if associated array have use string key/index instead of number. ex : $scope.trailers["numberone"]

if dont know key can use following code

for (var key in $scope.trailers) { console.log($scope.trailers[key]); } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

c# - Retrieve google contact -

javascript - How to insert selected radio button value into table cell -