从字符串数组ngResource请求无效结果 [英] Invalid result from ngResource request with string array
问题描述
我以下ngResource定义的:
i've the following ngResource defined:
angular.module('LicenseServices', ['ngResource']).
factory('License', function ($resource) {
return $resource('api/licenses/:id', { id: '@id' }, {
//...
'getLicenseTypes': { method: 'GET', url: 'api/licenses/types', isArray: true }
});
});
的
GET请求的结果是:
The result of the GET request is:
["Trial","Standard"]
但是,在一个控制器使用所述资源
But using the resource in a controller:
$scope.licenseTypes = License.getLicenseTypes()
我得到以下结果:
i get the following result:
licenseTypes:
[ undefined, {
0: S
1: t
2: a
3: n
4: d
5: a
6: r
7: d
} ]
我使用AngularJS 1.1.4浏览器。
I'm using AngularJS 1.1.4 with Chrome.
请告诉我错了我的资源定义?
Whats wrong with my resource definition?
推荐答案
有真的不是使用 $资源
像这些数据结构多点。问题是, $资源
的伟大工程,为REST风格的终点在哪里使用所有的HTTP动词。为了简单AngualarJS扩展了方便的方法传入的对象($保存,$删除等)。如果返回原语有和没有空间扩展 $资源的主要好处之一
已经一去不复返了。
There is really not much point in using $resource
for data structures like those. The thing is that $resource
works great for RESTful endpoint where all the HTTP verbs are used. To make this easy AngualarJS extends incoming objects with convenience methods ($save, $delete etc.). If you return primitives there is no room for extension and one of the major benefits of $resource
is gone.
在短期:如果你只是后获取数据$资源是矫枉过正海事组织,坚持使用 $ HTTP
而不是
In short: if you are just after fetching data $resource is an overkill IMO, stick with the $http
instead.
这篇关于从字符串数组ngResource请求无效结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!