The variable $scope.compdata i am not able to access outside the controller. Thanks in advance.
  var compdata;
  $scope.fetchCompanies = function() {
   var deferred = $q.defer();
   Company.get({
      arg1 : 'list',
      arg2 : 14
    }, function(success) {
      $scope.compdata = success.data;
      deferred.resolve(success.data); //Edited here
    });
    return deferred.promise;
  };
  $scope.fetchCompanies()
    .then(function(data) { // and this block
      $scope.compdata = data; //Added
      console.log("outside : ",  $scope.compdata) //success
    });
console.log("outside : ",  $scope.compdata); //undefined
 
    