0

I have the following state tree, using ui-router,

1 login
2 root (abstract, resolves app-prefs, user-prefs)
    2.1 home (builds a refresh button, should refresh whatever is being shown)
        2.1.1 dashboard (resolves dashboard-prefs)
        2.1.2 search (resolves search-prefs)
        2.1.3 etc
    2.2 etc

From home when user presses refresh button while in XYZ state, I would like to have the XYZ re-entered in such a way that it re-resolves its own XYZ-prefs but not things above in hierarchy. Something like

$state.go("dashboard", dashboardParams, {please-resolve-only-dashboard})

When I try, from home

$state.go("dashboard", dashboardParams, {reload:true})

that causes everything from root downwards to get re-resolved, which is problematic, and expensive, as I need to re-resolve only dashboard-prefs. I can setup a more elaborate scheme in some resolvers to not re-resolve themselves but that might become a task by itself I'm afraid. Is there another, more idiomatic way?

Thanks

Dinesh
  • 4,437
  • 5
  • 40
  • 77

1 Answers1

1

There is a wokring plunker

There is a native way how to do that - just change the parameter of the state you want to reload.

To reproduce the above state definition let's have dashboard defined like this:

.state('dashboard', { 
  parnet: 'home',
  url: "^/dashboard",
  params: { updater : 1, },
  ...
})

What we can see, that we do not touch url at all. It will always be without any change just /dashboard

But we introduce really cool feature of the latest version - params: {}. It defines some parameter - updater in our case. Whenever this parameter is sent, and does differ form its current value, this child state (and only this child state) is re-init

Check it more about state params: {} here: http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$stateProvider

Now, we can create this reload link:

<a ui-sref="dashboard({updater : ($stateParams.updater + 1) })">reload</a>

And with this incrementation, we can be sure, reload will reload this state

Check it here

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • Thanks, this works (+1) but I also see that a new scope is spun [updated plunkr](http://plnkr.co/edit/zSBeM6PH4BcM15OqfF8u?p=preview). How does one harvest previous controllers; in particular if any listeners were attached in the controller then the listeners live on, and the scope also lives on. – Dinesh Apr 15 '15 at 18:35
  • I think that's a different question. I will close out this one. – Dinesh Apr 15 '15 at 18:45