AngularJS: Restangular - How to remove request parameter from URL

I set the base API url in Main.js with the request parameter "advertiserId". I would like to remove the param advertiserId request in Demo.js. Note. I do not want to use the search parameters $location (since these are the search parameters from the current URL of the window, not the URLs that I built).

Main.js:

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

Demo.js

  Restangular.RemoveRequestParams({ "advertiserId": advertiserID }); 
+6
source share
2 answers

Could you also just reset the default to use an empty object in Demo.js?

 Restangular.SetDefaultRequestParams({}); 

I assume that the Restangular that you use in Demo.js is a newly created instance from the Restangular Service?

+1
source

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) ? you can use this:

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

Source: https://habr.com/ru/post/989501/


All Articles