I am trying to use an $http promise from a factory withing my controller. Code below works, and I can view the users variable in the view by calling {{users}}
Working Factory:
.factory('bidsCreatedSimple', ['$http', function($http) {
// Expose public API first, use func notation
return {
getUsers: getUsers,
};
function getUsers(){
return $http.get('/bids.json');
}
}])
In the controller:
$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
How can I use the $scope.users variable in my controller? I need to use it's data for some other objects in the controller.