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!

0

6 Answers 6

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.

Sign up to request clarification or add additional context in comments.

Comments

3

If you are using v 0.2.5

This is working . $state.reload()

Reference Link

Comments

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

Comments

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

Comments

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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.