0

这里有一个小问题,我有一个与工厂通信的控制器,但是如何将工厂结果传递给函数?我试过的东西:

.controller('testCtrl', ['$scope', 'foo', 'boo', function($scope, foo, boo){

     foo.get().then(function(response){
          $scope.foo = response;   
     });

     boo.get().then(function(response){
          $scope.boo = response;   
     });

     // Why this will not work?
     function test(){
          var getFoo = $scope.foo;
          var getBoo = $scope.boo; 
     };

}]

上面的例子不起作用,我怎样才能得到这个工作?

谢谢。

4

1 回答 1

0

献给派对后来的人。一个不使用的工作示例$scope

hoge.controller('testCtrl', ['$scope', 'foo', 'boo', function($scope, foo, boo){
  function test() {
     var getFoo = null;
     var getBoo = null; 

     Promise.all([foo.get(), boo.get()]).then(function(results) {
       getFoo = results[0];
       getBoo = results[1];
     });
   };
}]
于 2017-01-20T09:57:32.943 回答