$ route.reload () does not work with ui-router

I switched to ui-router . Everything went smoothly, except for one. On my page, I have a choice that changes the context of the application. In any case, earlier, when this context was changed, I executed this code (in particular, the 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() 

did the most important thing. He reloaded the page. But after switching to ui-router, $ route.reload does nothing. Also, I did not find an analog in the ui-router API. How to solve this problem?

+7
angularjs angular-ui-router
source share
5 answers

Works well when I inject $ state into the controller.

But when injecting it into services, such as a piece of code, of course $ state was undefined.

Although

 $state.go('.') 

does not work, I did something like this:

  $stateProvider .state('home', { controller: function ($state) { $state.go('advisoryLeadOffering.packages'); } }) .state('advisoryLeadOffering.packages', { url: "/packages", templateUrl: "/AdvisoryLeadOffering/Packages", controller: 'AdvisoryLeadOfferingPackages' }) 

and when I need to reboot, I do something like this:

 $state.transitionTo('home'); 

inner area method.

+5
source share

What about:

 $state.go($state.$current, null, { reload: true }); 
+36
source share

You can do $state.reload()

There, an error with it sometimes does not repeat the creation of the controller. You can get around this with

 $state.transitionTo($state.current, $stateParams, { reload: true, inherit: true, notify: true }); 
+7
source share

I had a similar problem when I needed a link outside the controller to update the state and just created the reload() function in the controller.

SomeCtrl :

 $scope.reload = function(){ $state.transitionTo('myState'); } 

Add this to your anchor:

 ng-click="reload()" 

H / T @dragonfly to indicate transitionTo() .

0
source share

The only thing that worked for me:

Create redirection state:

 $stateProvider.state('redirect', { url: 'redirect/:to', controller: function($state, $stateParams, $scope) { $state.go($stateParams.to, null, {reload: true}); } }); 

Go to this state:

 $state.go('redirect', {to: $state.current.name}, {reload: true}); 
0
source share

All Articles