0
$scope.order_details=function(index){
    var temp_order_id=$scope.order_data[index].order_id;
    $http.get('http://web.com/app/order_details/'+temp_order_id).then(function(response){
        $scope.order_details11=response.data.data;
        console.log($scope.order_details11);//Working Fine

    });
}
console.log($scope.order_details11);//return undefined

This is an angularjs code on which I am working on when I console the array inside the $http.get(...) it is working fine but when I try to access that array outside the function it is returning undefined

  • It is based on ajax call, but I don't want to use ajax call – Suraj Kumar Aug 16 '18 at 02:01
  • they only way to get more data from the server is to make another request and ajax allows you to do that. – Daniel A. White Aug 16 '18 at 02:02
  • this might be due to that service call happening.the below console would have executed before the service call is completed. Did you try adding a breakpoint and see the way it got executed. – Raphael Aug 16 '18 at 18:34
  • I hope the code is in controller, the console will get triggered once u load the controller and the method will get executed later when you actually trigger. – Raphael Aug 16 '18 at 18:38

1 Answers1

0

By "Working Fine" do you mean it actually logged $scope.order_details11 to the console or do you mean the code just compiles fine?

If it is the later (code simply compiling), I think it's because you have not executed the callback $scope.order_details, only defined it, and hence the attributed order_details11 in $scope is non-existent.