getRequestedUrl and getRestangularUrl not returning correct value for custom methods
Sorry for the long post, just wanted to provide as much info as possible.
I have a ReportApiModule and the following within the run method.
MyRestangular.extendCollection('reports', function (obj) {
obj.addRestangularMethod('getServiceReport', 'get', 'service-report');
return obj;
});
I then have a factory with that module called ReportApi where I return a service
return MyRestangular.service('reports');
MyRestangular is another factory/service utilising the Restangular.withConfig as per the docs.
In my controller I do this:
ReportApi.getServiceReport({from: '2015-08-01', to: '2015-08-31'})
.then(function(response) {
ctrl.data = response.data;
});
This calls http://{mysite}/reports/service-report?from=2015-08-01&to=2015-08-31
I then want to have an export button that hits the same url buts append &export=1 I was hoping I could create a function that looks like this:
function export() {
$window.location = ctrl.data.getRequestedUrl() + '&export=1';
// OR
$window.location = ctrl.data.getRestangularUrl() + '&export=1';
}
However both of these methods just return http://{mysite}/reports as the base url. getRequestedUrl() appends the params but not the service-report as per the custom method.
Is this a bug or am I doing something incorrectly?
I have the same problem:
var service = Restangular.withConfig(function(RestangularConfigurer) {
RestangularConfigurer.addElementTransformer('tasks', false, function(action_item) {
action_item.addRestangularMethod('addNotes', 'post', 'notes');
return action_item;
});
}).service('tasks')
// In my controller
$scope.task.addNotes([note]).then(function(task) {
console.log(task.getRequestedUrl());
console.log(task.getRestangularUrl());
// Both return myapi.com/notes not myapi.com/tasks
});
Same problem when directly using customGET(path).