title: angularjs $scope and $http
body: <p>I'm facing a strange problem, here is code:</p>
  
  <pre><code>$scope.registeredCompanies = []; 
  $scope.viewCompanies = function(){
      $http.get("server/loadCompanies.php").success(function(data){
          $scope.registeredCompanies = data;
          //console.log($scope.registeredCompanies);
          //1st log
      });
      console.log($scope.registeredCompanies);
      //2nd log
      $state.transitionTo('viewreRegisteredCompanies');
  }
  </code></pre>
  
  <p>And here is loadCompanies.php:</p>
  
  <pre><code>require "connection.php";
  $query = "select * from company where 1";
  $result = mysql_query($query);
  $companies = array();
  while($row = mysql_fetch_assoc($result))
      array_push($companies, $row);
  echo json_encode($companies);
  </code></pre>
  
  <p>Now, if I log <code>$scope.registeredCompanies</code> at 1st log i.e within <code>$http.get().success()</code>, it logs successfully i.e data is pulled successfully but if I log out of the promise/.success() i.e at 2nd log place, object again goes to no value i.e array gets empty or if I initialize array with some values, it logs those initial values to console, <strong>REMEMBER</strong> companies are more than one means there is no chance that PHP file returns zero record.</p>