AngularJS ui-router: force reload

前端 未结 5 1242
执笔经年
执笔经年 2020-12-30 00:59

I have an AngularJS app starting at index.html and using ui-router. Based on a trigger I want to reload the complete page. I tried:

$state.go($state.current,         


        
相关标签:
5条回答
  • 2020-12-30 01:22

    This worked for me in a similar scenario.

    $state.go('root.state').then(function(){
        $state.reload();
    });
    
    0 讨论(0)
  • 2020-12-30 01:29

    Everybody seems to have ignored what Serge van den Oever appears to actually be asking, and that's that he wants entire page to reload, and not just the route.

    The solution for that is pretty simple if you inject the $window service into your controller:

    $window.location.reload();
    

    If you just want the route to reload (which seems to be much more common), and are using ui-router, then just inject the $state service and do:

    $state.reload();
    

    This should reinitialize controllers now that the bug has been fixed, although I don't think it reinitializes resolves.

    0 讨论(0)
  • 2020-12-30 01:29

    Try this:

    $state.transitionTo($state.current, $stateParams, {
        reload: true,
        inherit: false,
        notify: true
    });
    
    0 讨论(0)
  • 2020-12-30 01:33

    If you include the $route service in your controller you could try $route.reload();

    0 讨论(0)
  • 2020-12-30 01:43

    The current trick is:

    $state.go($state.current.name, $state.params, { reload: true });

    0 讨论(0)
提交回复
热议问题