Reputation: 1011
I have an angular app where I use $state.go('state_name', stateParams)
.
The button which triggers state.go
event is always available at the page while url changes depending on stateParams
.
Everything works perfect until I pass the same stateParams object to $state.go
. In this case nothing happens at all. Looks like angular compares stateParams
in url and stateParams
object which I pass to state.go
and does nothing as values are the same. I expect $state.go
to perform the same action like it does when I pass state params object with values that do not match url.
I know that this can be solved with $state.go('state_name', stateParams, {reload: true})
but in my case this is what I don't really need as it reloads some parts of my applications which I don't need to reload.
Can anybody advise please how can I call state.go
with the same stateParams
object without reload: true so angular works as expected.
Upvotes: 1
Views: 374
Reputation: 5041
As per comments, here you have a code snippet that seems to do what you want. ie if you click in a link it will always go to that state, even if you are there with the same params:
myApp.config(function ($provide) {
$provide.decorator('$state', function ($delegate) {
// let's locally use 'state' name
var state = $delegate;
// let's extend this object with new function
// 'baseGo', which in fact, will keep the reference
// to the original 'go' function
state.baseGo = state.go;
// here comes our new 'go' decoration
var go = function (to, params, options) {
options = options || {};
// only in case of missing 'reload'
// append our explicit 'true'
if (angular.isUndefined(options.reload)) {
options.reload = true;
}
// return processing to the 'baseGo' - original
this.baseGo(to, params, options);
};
// assign new 'go', right now decorating the old 'go'
state.go = go;
return $delegate;
});
})
Upvotes: 1