0
我想用我的控制器从工厂使用$ http诺言。下面的代码工作,我可以通过调用{{users}}
工作厂查看该用户在视图中的变量:
.factory('bidsCreatedSimple', ['$http', function($http) {
// Expose public API first, use func notation
return {
getUsers: getUsers,
};
function getUsers(){
return $http.get('/bids.json');
}
}])
在控制器:
$scope.users = []; //visible in the view
activate();
function activate(){
bidsCreatedSimple.getUsers().then(function(users){
$scope.users = users.data;
});
}
console.log($scope.users); //returns a blank [] even though
//it renders with data in the view
我如何使用$范围。用户变量在我的控制器?我需要将它的数据用于控制器中的其他对象。
没错,但我在控制器中有一堆使用'$ scope.users'的对象。例如'$ scope.gridOptions.data'需要设置为'$ scope.users',以便库能够渲染网格。我将如何将这些变量设置为用户数据? – HoosierCoder
你使用angular-ui吗?我没有使用它,但你可能可以设置对$ scope.users的引用,然后使用一些刷新方法或类似的东西。像http://stackoverflow.com/questions/26634063/how-to-use-refresh-method-in-ui-grid –
但是,我将如何实际使用控制器中的数据?我需要将它传递给一些服务,这将操纵它 – HoosierCoder