AngularJS $ stateParams when using reloadOnSearch: false
I have a page in my application that uses search, so I added "realoadOnSearch: false" which works great
The problem is going to the same state with a different stateParam:
when i go to # / category / 20 / from any other page it works fine ... then i have a link on that page: # / category / 3 (parent category for 20) and urls updates, however the content is not contains (no errors in the console)
app.js (main application)
.state('category', {
url: '/category/:categoryId/',
templateUrl: '/Home/Category',
controller: 'categoryCtrl',
reloadOnSearch: false
})
I tried adding target = "_ self" to reload the page and it doesn't work
I also tried looking at $ stateParams for changes and nothing happened
By clicking on the # / category / 3 link from # / category / 20 (and vice versa), go to a new page and reload the data, where the search should NOT reload the page (the last one works, but not the first one)
The url is preferred: ng-href over ng-click as it is driven by the root controller
EDIT:
I didn't find a direct solution, but I just disabled reloadOnSearch and my sort buttons still work, so now this works as a solution for me.
source to share
The problem is that reloadOnSearch
it doesn't do what you think it does; it's more like reloadOnStateParams
. Setting it to false prevents you from making state changes where only stateParams
what you do here (from #/category/3
to #/category/20
) changes .
You can see this is documented on the UI router issues page: https://github.com/angular-ui/ui-router/issues/1079
There are workarounds out there, but none of them are great. You are probably best off using ng-click, which forces you to reload manually, something like this:
$state.transitionTo($state.current, $stateParams, {
reload: true,
inherit: false,
notify: true
});
source to share