在$资源URL查询字符串 [英] query string in $resource url
问题描述
我的服务必须使用一个查询字符串由于运行传统的ASP服务器上的限制:
my service has to use a query string due to limitations on the server that runs classic ASP:
angular
.module('myServices', ['ng', 'ngResource'])
.factory('Item', ['$resource',
function ($resource) {
return $resource('/api/?p=item/:id');
}]);
和我想要额外的查询字符串参数添加到它:
and I want to add extra query string parameters to it:
Item.query({test: 123}, on_success, on_error);
但得到的URL
but the resulting url is
/api/?p=item?test=123
显然是有缺陷的,但如何解决它?
apparently there is a bug, but how to get around it?
编辑:提起这个在<一个href=\"https://github.com/angular/angular.js/issues/1511\">https://github.com/angular/angular.js/issues/1511
推荐答案
您可以使用资源参数。如果你还没有在指定的路径占位符,他们将被自动转换成查询字符串PARAMS。这样的:
You can use resource parameters. If you haven't specified placeholders in the path, they would automatically be converted into query string params. Like that:
angular
.module('myServices', ['ng', 'ngResource'])
.factory('Item', [
'$resource',
function ($resource) {
return $resource('/api');
}]);
Item.query({p: 'item/1'});
这将导致以 / API?P =项/ 1
。
P.S。
我想你已经知道了,但你不喜欢它。但我仍然认为这是你的情况的正确方法。考虑到你正在处理的后端,你可以用它为您完成此另一个服务包住AngularJS资源不好的API设计。
I suppose you already know that, but you don't like it. But I still think this is the correct way in your case. Considering the bad API design you are dealing with that back-end you could wrap the AngularJS resources with another service which does this for you.
这篇关于在$资源URL查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!