restangular icon indicating copy to clipboard operation
restangular copied to clipboard

fix(service): Custom getRestangularUrl() and getRequestUrl() - #1216

Open nonplus opened this issue 9 years ago • 2 comments

fix(service): Custom getRestangularUrl() and getRequestUrl() - #1216

nonplus avatar Nov 21 '16 12:11 nonplus

@nonplus Thanks! Can you describe what this PR is about and why we need it?

bostrom avatar Nov 21 '16 13:11 bostrom

It addresses the problem described in #1216.

Personally, I want to be able to (periodically) re-fetch a Restangular resource. I should be able to do something like this:

RestangularProvider.setOnElemRestangularized((elem, isCollection) => {
	if (!isCollection) {
		elem["fetch"] = function() {
			return this.get(this.reqParams);
		};
		elem["refresh"] = function() {
			return this.fetch()
				.then(value => angular.copy(value, this));
		};

	}
	return elem;
});

This works fine for one/all resources, but doesn't work for resources returned by customGET("path") or methods added via addRestangularMethod("methodName", "GET", "path") because Restangular incorrectly doesn't include "path" in the URL used by get().

nonplus avatar Nov 21 '16 13:11 nonplus