2017-04-27 36 views
0

我有这样的代码在角工厂:如何在AngularJs Sdk环回工厂中发送数据?

getPermissions: function(modelId){ 

var Pers = Permission.find({ 
    filter : { 
     where : { 
      and : [ 
      { 
       user_id : $rootScope.userId 
      }, 
      { 
       permission_id : modelId 
      } 
      ] 
     } 
    } 
}, function(data){ 
    var Pers = data; 
}); 

console.log(Pers); 
}, 

但在控制台中我得到:

[$promise: c, $resolved: false] 

而且在我的应用程序功能:

$scope.optionsCrud = getFoo.getPermissions(2); 

console.log($scope.optionsCrud); 

我在控制台中

undefined 

我无法成功运行数组。

我该怎么办?

回答

0

您应该返回Pers一样,

console.log(Pers); 
return Pers; 

完整的代码,

getPermissions: function(modelId){ 
    var Pers = Permission.find({ 
     filter : { 
      where : { 
       and : [ 
       { 
        user_id : $rootScope.userId 
       }, 
       { 
        permission_id : modelId 
       } 
       ] 
      } 
     } 
    }, function(data){ 
     var Pers = data; 
    }); 
    console.log(Pers); 
    return Pers; 
}, 

,然后让喜欢你的数据,

$scope.optionsCrud = getFoo.getPermissions(2); 
$scope.optionsCrud.$promise.then(function(data){ 
// or just use, $scope.optionsCrud.then if not works 
    console.log(data); 
}); 
+0

还好现在不是不确定的,但我仍然得到' [$ promise:c,$ resolved:false]'并且我不知道如何在阵列上运行 – oded

+0

试试我的更新回答。 –

+0

感谢它的工作 – oded