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

前端 未结 5 1407
北海茫月
北海茫月 2020-12-28 23:12

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

相关标签:
5条回答
  • 2020-12-28 23:41

    How about:

    $state.go($state.$current, null, { reload: true });
    
    0 讨论(0)
  • 2020-12-28 23:44

    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:

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

    Add this to your anchor:

    ng-click="reload()"
    

    H/T @dragonfly for pointing me to transitionTo().

    0 讨论(0)
  • 2020-12-28 23:49

    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.

    0 讨论(0)
  • 2020-12-28 23:51

    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 });
    
    0 讨论(0)
  • 2020-12-28 23:55

    The only thing worked for me:

    Create redirect 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 讨论(0)
提交回复
热议问题