3

I'am using Angular JS with UI-Router,

I want to reload state, when we click on the state link from the same state.

I fixed it with the following code,

<a ui-sref="page1" ui-sref-opts="{reload: true}">Page 1</a>

But it is tedious to add ui-sref-opts="{reload: true}" in all the links.

So I want a configuration or settings or code in angular js( or ui-router) to manage this globally. That is if we click on state link from the same state, the state should get reloaded.

Please help me to find a solution.

3
  • You can write your own directive that will do that Commented May 24, 2016 at 5:46
  • do you want to reinitialize the controller with the newly resolved values ? Commented May 24, 2016 at 5:55
  • @dennyjohn : yes, I want to reinitialize controller Commented May 24, 2016 at 6:47

1 Answer 1

2

The way to go here is to adjust $state.go implementation, e.g. like this:

Changing the default behavior of $state.go() in ui.router to reload by default

In general we will use decorator to get control over $state behaviour

.config(function ($provide) {
    $provide.decorator('$state', function ($delegate) {

        // let's locally use 'state' name
        var state = $delegate;
        ...

see that in action here

Why that should work is described here:

Difference between ui-sref and $state.go in AngularJS UI-Router

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.