I'm having troubles making an http request in angular js. I know the call is being made because I can see the response in firebug which is,
[{"cube":"1" ,"points":"160"},{"cube":"2","points":"690"},{"cube":"3","points":"331"}]
I am going off this tutorial, link.
Thus my code looks like this.
Note I put in comments where I'm having troubles. My main question is why isn't the console.log working? How can I get it to work? How can I have $scope.usersPerCube assigned to the json that is being returned by the network request?
var myApp = angular.module('test', []);
myApp.controller('UserCtrl', function($scope, users) {
users.getUsers().then(function(data) {
//not working
$scope.usersPerCube = data;
//this isn't getting logged
console.log(data);
});
//this is getting logged and returning [object Object] which is the promise
console.log(users.getUsers());
})
myApp.factory('users', function($http) {
return {
getUsers: function() {
var url = "http://localhost/index.php/analytics/UsersPerCube"
return $http.jsonp(url).then(function(result) {
//this is not getting logged as well...
console.log(result+ "logging from http");
return result.data;
});
}
}
});