嗨,我想知道是否有人可以帮助我更改查询字符串的格式。目前它的格式如下:
/api/foo?id=AD12JK23
但是我该如何将其更改为以下格式:
/api/foo/AD12JK23
我的代码如下:
.state('foo-details', {
url: '/foo-details/:fooRefrence'
}
})
var ref = $stateParams.fooRefrence;
$scope.fooDetails = myApi.Foo.get(
{
id: ref
}
);
.factory('myApi', ['$resource', function ($resource) {
return {
Foo: $resource('/api/foos', {id: '@ref' },
}
}])
感谢您的帮助。
最佳答案
查看资源引用以了解执行此操作的适当方法。 https://docs.angularjs.org/api/ngResource/service/$resource#usage
我想如果你这样写你的资源url,就能解决问题:
.factory('myApi', ['$resource', function ($resource) {
return {
// Add :id at the end of the url
// Also change @ref to @id, the word you use after @ is the same as
// the key of the object you use to call the resource with
Foo: $resource('/api/foos/:id', {id: '@id' },
}
}])
关于javascript - Angular $resource 从 REST 查询字符串中删除问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25743497/