How to change the parameters of $ routeParams?

Im referring to this URL: http://bazarak.af/#!/annonser/page=1& ...

.when("/annonser/:query",{ templateUrl: '/views/search.php', controller: "Search" }) 

I would like to get the value of the page and change it in both the URL and routeParams.

To get the value of the page I tried

 var pageNumber = $routeParams.page; 

and to install it, I tried:

 $routeParams ==> {page:5} 

None of this is happening. And the documentation doesn't really help me. How can i do this?

+4
source share
3 answers

Use $ location.path () to set a new URL path. This will affect the routes. You can also just change $ location.search to change your request. Read this documentation http://docs.angularjs.org/guide/dev_guide.services . $ location

+6
source

Using $location.path() requires that you can give it a hole path, including search parameters and a hash, so you will need to parse the url to change one parameter in the middle of the url, like this /user/:id/inbox/:read , then its easier to use:

 // given the current url is http://example.com/user/3/inbox/unread?sort=desc $route.updateParams({id:"2"}); // will become http://example.com/user/2/inbox/unread?sort=desc 
+7
source

You can also use the following to clear all route parameters from the URL:

 var myParams = new Object(); for(var param in $routeParams){ myParams[param] = null; } $route.updateParams(myParams); 
0
source

All Articles