Angularjs-重新启动工厂/服务内部的Angular调用

Angularjs-重新启动工厂/服务内部的Angular调用,angularjs,scope,angularjs-service,restangular,angularjs-factory,Angularjs,Scope,Angularjs Service,Restangular,Angularjs Factory,我使用的工厂如下: var appModule = angular.module('appModule', ['ngRoute','restangular']); appModule .config(['$routeProvider', function($routeProvider) { $routeProvider .when('/home', { templateUrl: 'home.html', controller: 'ngH

我使用的
工厂
如下:

var appModule = angular.module('appModule', ['ngRoute','restangular']);

appModule
  .config(['$routeProvider', function($routeProvider) {
    $routeProvider
      .when('/home', {
        templateUrl: 'home.html',
        controller:  'ngHomeControl'
      })
      .when('/contacts', {
        templateUrl: 'contacts.html',
        controller:  'ngContactControl'
      });
  }]);

appModule
  .factory('testFactory', function testFactory(Restangular) {
    return {
      getFriendList: function() {
        return Restangular
          .all('api/users/getfriendsinvitations/')
          .getList()
          .then(function(response) {
            //
          });
      } 
    }
  });

appModule
  .controller('ngHomeControl', function($scope, testFactory) {
    $scope.homeFriends = testFactory.getFriendList();
  });

appModule
  .controller('ngContactControl', function($scope, testFactory) {
    $scope.contactFriends = testFactory.getFriendList();
  });
在这里,我无法从
restanglar
调用中获取
$scope.homeFriends
$scope.contactFriends
的值。有谁能建议我如何使用
工厂
/
服务
重新启动的
调用中获取值吗?

最后我发现:

appModule
  .factory('testFactory', ['Restangular', function(Restangular) {
    return {
      getFriendList: Restangular
        .all('api/users/getfriendsinvitations/')
        .getList();
    }
  }]);

testFactory.getFriendList.then(function(homeFriends) {
  $scope.homeFriends = homeFriends;
}

由于getFriendList方法返回承诺,您可能需要使用
然后
回调绑定到列表。