Here is my method inside a controller, i want to access the $scope.oldcats  outside the below given method. 
Using console.info($scope.oldcats); inside the method, outputs the data, 
but using console.info($scope.oldcats); outside function display undefined.
$scope.loadPost = function() { //Issues a GET request to /api/post/:id to get a Post to update
    $scope.posts = Post.get({ id:$stateParams.id}, function(response){
       $scope.posts = response.data;
       $scope.posts.selcats = response.data.categories;
       var cats = $scope.posts.categories;
       $.each(cats, function(arrayID,group) {
           $scope.allCats.push(group.id);
       });
       $scope.oldcats = $scope.allCats; // <- i want to access it
       console.info($scope.oldcats); // <- output displays data
   });
  };
  $scope.loadPost(); // Load a Post which can be edited on UI
  console.info($scope.oldcats); // <- output display undefined
 
     
    