angular js で http リクエストを作成する際に問題があります。firebug で応答を見ることができるので、呼び出しが行われていることがわかります。
[{"cube":"1" ,"points":"160"},{"cube":"2","points":"690"},{"cube":"3","points":"331"}]
このチュートリアルを終了します。リンク.
したがって、私のコードは次のようになります。
私が問題を抱えているところにコメントを入れたことに注意してください。私の主な質問は、console.log が機能しないのはなぜですか? どうすれば動作させることができますか? ネットワーク要求によって返される json に $scope.usersPerCube を割り当てるにはどうすればよいですか?
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;
});
}
}
});