Is there a way to retrieve a single result from my array $scope.trailers
? I am encountering an issue where accessing the first index using $scope.trailers[0]
returns undefined. The API call is made using ngResource.
function getTrailers(pageNo){
pageNo = typeof pageNo !== 'undefined' ? pageNo : 1;
$scope.trailers = apiservice.getTrailers().query({page: pageNo});
vm.trailer = $scope.trailers[0];
};
The structure of $scope.trailers
: https://i.stack.imgur.com/105uv.jpg
It appears that the issue lies in the asynchronous nature of the call. How can I create a promise for the query within the getTrailers
function?