5

I setup API base url in Main.js with query param "advertiserId". I would like to remove the query param advertiserId in Demo.js. Note I don't want to use $location search params (since these are search params from current window URL not the URL I constructed).

Main.js:

  Restangular.setBaseUrl("localhost:9000/advertisers");
  Restangular.setDefaultRequestParams({
    "advertiserId": advertiserID
  });

Demo.js

 Restangular.RemoveRequestParams({
    "advertiserId": advertiserID
 });

2 Answers 2

1

Couldn't you also just reset the defaults to an empty object in Demo.js?

Restangular.SetDefaultRequestParams({});

I'm guessing that the Restangular you're using in Demo.js is a newly created instance from the Restangular Service?

Sign up to request clarification or add additional context in comments.

Comments

0

You can parse any url with this:

var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";

parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port;     // => "3000"
parser.pathname; // => "/pathname/"
parser.search;   // => "?search=test"
parser.hash;     // => "#hash"
parser.host;     // => "example.com:3000"

EDIT: To remove everything after (and including) the ? you can use this:

url.split("?")[0];

1 Comment

Thanks Michelem. Is there any way to remove parser.search from the URL?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.