dzm
dzm

Reputation: 23544

angular-ui router reload view

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!

Upvotes: 6

Views: 9612

Answers (6)

Lukas Cerny
Lukas Cerny

Reputation: 52

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.

Upvotes: 0

Fizer Khan
Fizer Khan

Reputation: 92745

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 });

Upvotes: 1

Nishchit
Nishchit

Reputation: 19074

If you are using v 0.2.5

This is working . $state.reload()

Reference Link

Upvotes: 3

Richard
Richard

Reputation: 1172

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.

Upvotes: 7

Tim Kindberg
Tim Kindberg

Reputation: 3635

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.

Upvotes: 0

Nikola Yovchev
Nikola Yovchev

Reputation: 10226

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

Upvotes: 0

Related Questions