Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 781
dragonfly Avatar asked Oct 25 '13 07:10

dragonfly


3 Answers

How about:

$state.go($state.$current, null, { reload: true });
like image 69
devdave Avatar answered Nov 12 '22 07:11

devdave


You can do $state.reload()

There's a bug with it sometimes not re-instantiating the controller. You can get around that with

$state.transitionTo($state.current, $stateParams, { reload: true, inherit: true, notify: true });
like image 21
Will Stern Avatar answered Nov 12 '22 06:11

Will Stern


Ok it works when I inject $state into controller.

But when injecting it into service like code snippet, of course $state was undefined.

Although

$state.go('.')

did 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 reload I do something like this:

$state.transitionTo('home');

inside scope's method.

like image 6
dragonfly Avatar answered Nov 12 '22 05:11

dragonfly