I have a controller, with a route like this:
#/articles/1234
I want to change the route without completely reloading the controller, so I can keep the positi
You can use the $location.search()
method as you mentioned. You should listen to the "$routeUpdate"
event on scope instead of other route events. $route API.
First of all (you already know), add reloadOnSearch: false
to your $routeProvider
:
$routeProvider.when('/somewhere', {
controller: 'SomeCtrl',
reloadOnSearch: false
})
Change your anchor tag href
or ng-href
to href="#/somewhere?param=value"
this will trigger $routeChangeSuccess
event if the path part (/somewhere
) is not the same as current location. Otherwise it will trigger $routeUpdate
event.
Listen event on scope:
$scope.$on("$routeUpdate", function(event, route) {
// some code here
});
If you want to change search params in code, you can use $location.search()
method. $location.search API.