Angularjs - 资源返回承诺

Angularjs - Resource returning promise

请记住我是 AngularJS 的初学者。我按照 angularjs 站点上的教程进行操作,并尝试将那里的内容应用到我自己的项目中。 我正在尝试使用 $resource 从 json 获取数据,我从 API 获取数据,如下所示:

类别服务:

angular.module('core.category') 
.factory('Category', ['$resource', '$http',
    function($resource, $http) {
        return $resource('/api/categories', {}, {
            query: {
              method: 'GET',
              isArray: true
            }
        });
    }
]);

转到 url URL/api/categories return 一个 JSON 这种格式:

[{"id":1,"name":"name","desc":"desc"}]

在一个组件中,我使用它来检索 json:

self.categories = Category.query();
console.log(self.categories);

我在控制台中得到的不是 json 格式的数据:

[$promise: Promise, $resolved: false]

我试过这个:

Category.query().$promise.then(function(data) {
   console.log(data);
});

得到这个:

[$promise: Promise, $resolved: true]

为什么不获取json中的数据?难道是因为我是 运行 一个 php 服务器?我怎样才能以 Json 格式从 API 中检索数据?

谢谢

I've tried the same code as yours and have [Resource, $promise: Promise, $resolved: true] (while using $promise.then) where first Resource element is {id: 1, name: "name", desc: "desc"}. So you have to check the actual response of your web server as @yBrodsky assumed.

感谢@yBrodsky 和@StanislavKvitash。我已经解决了这个问题。这是我的网络服务器的问题。