SheppardPL
SheppardPL

Reputation: 85

How to reload state using angular-ui-router?

How to reload a controller and entire side using angular-ui-router?

$state.reload() or $state.go('myState')

does not work. Only method which works is:

$state.go('anotherState');
$state.go('myState');

Regards

Upvotes: 1

Views: 402

Answers (2)

Mayur Agarwal
Mayur Agarwal

Reputation: 854

I found this to be the shortest working way to refresh with ui-router:

$state.go($state.current, {}, {reload: true}); //second param is for $stateParams if you have any.

New versions also support this:

$state.reload();  

Which is an alias for:

$state.transitionTo($state.current, $stateParams, { 
  reload: true, inherit: false, notify: true
});       // this is also used to reload the controller and view without page reload.

Documentation: https://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state#methods_reload

Upvotes: 1

Ankit Agarwal
Ankit Agarwal

Reputation: 30739

You can use this without page refresh. This will reload the view:

$state.transitionTo($state.current, $stateParams, {
    reload: true,
    inherit: false,
    notify: true
});

or else try this

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

Upvotes: 1

Related Questions