ngResource.myfunc().$promise.then returns 空数组

ngResource.myfunc().$promise.then returns empty array

我正在使用 angularjs-1.5.0 编写我的应用程序。

我创建了一个使用 $resource 从 api 服务器获取数据的服务。该服务称为 MyApi。

(function () {

angular.module('myalcoholist').factory('MyApi', ['$resource', '$auth', function ($resource, $auth) {
    return $resource('https://myalcoholist.com:8888/drink/:cmd',
        null, {
                 pouringSpeedTypes: {
                method: 'GET',
                params: {api_token: $auth.getToken(), cmd: 'get_pouring_speed_types'},
                isArray: true
            },
            pouringLocationTypes: {
                method: 'GET',
                params: {api_token: $auth.getToken(), cmd: 'get_pouring_location_types'},
                isArray: true
            }
        });
        });
}]);

})();

在我的控制器中,我使用以下代码使用此服务:

 MyApi.pouringLocationTypes().$promise.then(function(data) {
        console.info(data);
    });
    MyApi.pouringSpeedTypes().$promise.then(function (data) {
        console.info(data);
    });

问题是数据是..我猜是一个承诺。 这是数据包含的内容:

$promise: d
$resolved: true
length: 0
__proto__: Array[0]

我该怎么办?如何从 get 请求中获取实际数据?

感谢您的评论,您让我查明了问题所在。

首先,我没有更新我的服务器代码,这就是为什么当您尝试这些地址时,您得到的是 Method not Allowed。

我遇到的问题是这些请求实际上返回了空数组。

所以首先我的 API returns 一个 json 对象不是数组所以我将 isArray 更改为 false。

所以在那之后并实际修复了我的 API 服务器,这是我收到的:

$promise: d
$resolved: true
data: Array[4]
success: true

my API server returns a json with data and success.所以现在一切正常!非常感谢。