Since angular v.1.2.14 this issue has been fixed. Update to it and have a clear url without unnecessary question
AngularJS $resource url causes "question mark" ? to appear with no params
-
01-07-2022 - |
Вопрос
I have a $resource that defines a custom url for the :all method.
angular.module('MyApp').
factory('Object', ['$resource', ($resource) ->
$resource(
'/api/groups/:group_id/objects/:id.json',
{
id: '@id',
group_id: '@group_id'
},
all: {
method: 'GET',
url: '/api/objects/all.json'
}
)
])
When my page loads, the request goes out to '/api/objects/all.json?'. It's loading correctly, but the presence of the ? is confusing to me. I didn't pass it any parameters, so why does angular add the ? to the request?
Can I get rid of it somehow?
Решение
Другие советы
You should move your top level parameters into the method that will be expecting an id into the definition of a get method. Since you have { id: @id } where it is, the resource service is thinking you'll be adding an id and group id to the call.
Не связан с StackOverflow