1

I'm using angular-ui-router to manage router of my webapp, here got a question...

How can I do reload when I click the same link, currently when I click a link twice that just load one time...

Jason_tjc
  • 27
  • 5
  • Can you elaborate on your question? Share some code that you have that is relevant to the question. – iulian Apr 15 '16 at 07:02
  • is [`$state.reload()`](http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state) is what you are looking for? Scroll to the `reload` method in the documentation and see whether it's what you need – iulian Apr 15 '16 at 07:11
  • See this: http://stackoverflow.com/a/24458344/1414641 – D_S_toowhite Apr 15 '16 at 08:40
  • Reloading is probably not what you want to do. It is considered bad practice and there is probably a better way to achieve your desired result. Please post some more details about your problem to get a better answer. – henrikmerlander Apr 15 '16 at 08:58
  • Please have a look at the following link : http://stackoverflow.com/questions/21714655/reloading-current-state-refresh-data/29384813#29384813 . This is what you need. – Vaibhav Pachauri Apr 15 '16 at 09:42

1 Answers1

4

Probably the cleaner approach would be the following :

<a data-ui-sref="awesomeStateName" data-ui-sref-opts="{reload: true}">Details State</a>

We can reload the state from the HTML only.

Vaibhav Pachauri
  • 2,671
  • 2
  • 19
  • 32
  • so do I need to add something like: params: {reload: false} into stateProvider of this relative router? – Jason_tjc Apr 16 '16 at 09:38
  • You just need to use 'data-ui-sref-opts="{reload:true}" in your anchor link. This directive is provided by the ui-router itself where you can actually reload the state on click of this particular anchor link. – Vaibhav Pachauri Apr 16 '16 at 11:33
  • Thank you for your answer, It's working! BTW what different bewteen 'ui-sref' and 'data-ui-sref' – Jason_tjc Apr 18 '16 at 01:21
  • since ui-sref, ng-app or any other directive are not HTML5 compatible. So to make it HTML5 compatible we prefix 'data-' before all the angular directives. It is considered to be a good practice. And HTML5 compilers does't throw warnings. Hope that answers your query. – Vaibhav Pachauri Apr 18 '16 at 02:51
  • I see!Thank you every much! – Jason_tjc Apr 18 '16 at 06:53