1

How can I do this in Angular:

window.location.href = window.location.href + "/?id = 123";

So append new paramater to the end of the url and refresh the page(without loading it from cache).

2 Answers 2

4

You can use $location for that.

Example: $location.search('id','123)

That is going to append ?id=123 to the current page url and do a soft refresh.

Then to do a hard refresh you can do location.reload()

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

4 Comments

$location.search('id','123') works as expected but after doing location.reload(), the appended params is removed from the url.
Are you using ui-router for routing?
No, I'm using ngRoute
I have the same issue. Did you find a solution?
0

Use $window :

$window.location.href = $location.path() + "/?id = 123";

Or use $location :

$location.url($location.path() + "/?id = 123");

The results are same, only view is reload by angular, this is not a force refresh by the browser.

Comments

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.