I've switched to to ui-router. Everything went smoothly, except one thing. On my page I have a select that changes the context of the application. Anyway, previously, when this context was changed I was executing this code (in particular, set method):
'use strict';
angular.module('main').factory('lacContext', ['$route', function ($route) {
return {
set: function (id) {
sessionStorage.setItem("lac-context", id);
$route.reload();
},
get: function () {
return sessionStorage.getItem("lac-context");
}
};
}])
and
$route.reload()
was doing the most important thing. It reloaded the page. But after switching to ui-router, $route.reload does nothing. Also I did not find counterpart in ui-router API. How to solve this issue?
The only thing worked for me:
Create redirect state:
Go to this state:
Ok it works when I inject $state into controller.
But when injecting it into service like code snippet, of course $state was undefined.
Although
did not work, I did something like this:
and when I need to reload I do something like this:
inside scope's method.
You can do
$state.reload()
There's a bug with it sometimes not re-instantiating the controller. You can get around that with
I had a similar problem where I wanted a link outside of the controller to refresh a state and just created a
reload()
function in the controller.SomeCtrl
:Add this to your anchor:
H/T @dragonfly for pointing me to
transitionTo()
.How about: