6

I'm using angular-ui's router (v0.2.0) in a project and we're trying to reload a view. I've tried $state.transitionTo and also $state.go, but neither seem to do anything. Would anyone know how to do a reload?

Thank you!

dzm
  • 22,844
  • 47
  • 146
  • 226

6 Answers6

7

The 3rd parameter of $state.go takes an options object which has a reload property, so doing something like

$state.go('resources', {start: $stateParams.start}, {reload:true});

Should do the trick - on the latest version I can confirm it works.

Richard
  • 1,162
  • 1
  • 11
  • 19
3

If you are using v 0.2.5

This is working . $state.reload()

Reference Link

Nishchit
  • 18,284
  • 12
  • 54
  • 81
1

In Angular UI route v0.2.5, there is a third parameter reload

  $state.transitionTo(to, toParams [, options])
  $state.go(to, toParams [, options])

Third parameter is optional.

  $state.go('contacts', {sort: 'name' }, { reload: true });
Fizer Khan
  • 88,237
  • 28
  • 143
  • 153
0

If you are going from state A to state A again, the internals of the angular-ui would forbid it from reloading the state. You'd have to go to a different state to have a reload. That is to avoid clicking many times on the same link issuing a reload.

You can try switching to the same state, but with slightly different params, if you are that desperate to reissue a reload. But in my point of view, if you are in the same state, a reload shouldn't happen.

There is already also a similar question on SO: $route.reload() does not work with ui-router

Community
  • 1
  • 1
Nikola Yovchev
  • 9,498
  • 4
  • 46
  • 72
0

If you are ok with using grunt and building yourself there is a new $state.reload() feature. Or you can wait until v0.3 coming soonish.

Tim Kindberg
  • 3,605
  • 1
  • 25
  • 26
0

Comment on similar question Reloading current state - refresh data by SimplGy:

Probably worth noting that none of these [edit: meaning $state.transitionTo('state'), $state.reload() or $state.go($state.current, {}, {reload: true})] actually reload the page as well. If you want to reload the state AND the page, there is no ui-router method for it I think. Do window.location.reload(true)

Another comment by edhedges improved this one by mentioning the use of

$window.location.reload()

Which works and I recommend using for the reloading a ui-view.

Community
  • 1
  • 1