我是angularjs的新手,我试图在$ http中使用$ scope有问题 . 在$ http里面我可以看到数据,但在外部服务我得到null .

服务器内的Console.log($ scope.data)我获取数据:

enter image description here

外部的Console.log($ scope.data)始终为null:

enter image description here

我的代码:

(function (app, ng) {
  'use strict';

  app.controller('mainController', ['$scope', 'ServicePatient', function ($scope, ServicePatient) {
    $scope.data = null;
    ServicePatient.all().success(function (data) {
      $scope.data = data;
    });
    $scope.sortType     = 'last_Name'; // the default sort type
    $scope.sortReverse  = false;  // the default sort order
    $scope.search  = '';     // the default search/filter term
    $scope.filterEnabled = '';
    $scope.setEnabled = function(status){
    $scope.filterEnabled = status;
    if(status){
      angular.element(document.querySelector( '#enabledFalse')).removeClass('active-btn');
      angular.element(document.querySelector( '#enabledTrue')).addClass('active-btn');
    } else {
      angular.element(document.querySelector( '#enabledTrue')).removeClass('active-btn');
      angular.element(document.querySelector( '#enabledFalse')).addClass('active-btn');
    }  
  }

  console.log($scope.data);

  }]);

  app.service('ServicePatient', ['$http', function ($http) {
    function all() {
      return $http({
        url: 'http://54.165.192.65/ekare/ws6.php?request=patient',
        method: 'GET'
      });
    }

    return {
      all: all
    }
  }]);
}(angular.module('app', []), angular));