Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$state.reload does not work if state have reloadOnSearch:false #1803

Closed
JobaDiniz opened this issue Mar 6, 2015 · 23 comments
Closed

$state.reload does not work if state have reloadOnSearch:false #1803

JobaDiniz opened this issue Mar 6, 2015 · 23 comments
Labels
Milestone

Comments

@JobaDiniz
Copy link

My website has a header which contains a search field. This header is always shown, doesn't matter which state is the current state. When one submit the search form, they are redirected to search state with term param.

The search page (state) shows pagination widget, so when user clicks page 2, I change the query string but don't reload the state (that's why I use reloadOnSearch:false). However, the search form is still in the page. If user submits another search, only the term parameter will change and because of that, the page will not be reloaded. But I need to reload the page if user submits the search again.

I've created a simple plunker to demonstrate.

I think $state.reloadshould reload the state, even if it has reloadOnSearch:false.
I'm migrating from ngRoute, and $route.reload() reload the route even if it has reloadOnSearch:false.

@alexndlm
Copy link

@ptrussart
Copy link

Hello,

I have the same issue here.
Did you find a workaround ? Is there a way to set temporarily reloadOnSearch:true on the $state object ?

@JobaDiniz
Copy link
Author

Unfortunately, I had to reload the entire page... So not user friendly....

@the-darc
Copy link

I have the same issue here.

I think the problem cold be in the code below (called by the function $state.transitionTo):

  function shouldTriggerReload(to, from, locals, options) {
    if (to === from && ((locals === from.locals && !options.reload) || (to.self.reloadOnSearch === false))) {
      return true;
    }
  }

https://github.com/angular-ui/ui-router/blob/master/src/state.js#L1375

Note that in the if, the value of options.reload is not considered if the reloadOnSearch is setted to false.

When I have some time i pretend to do more tests and post a PR. If anyone want to do it before me, be free

@mkaluzny
Copy link

+1

1 similar comment
@minmur
Copy link

minmur commented Apr 14, 2015

+1

@nateabele
Copy link
Contributor

Looks like a valid issue, but reloadOnSearch is actually going away to be replaced with something much better. Y'all think you can hold out for a bit?

@minmur
Copy link

minmur commented Apr 15, 2015

Is there any date when it will happen?

@nateabele
Copy link
Contributor

As soon as possible. 😉 Trying for the middle of next week.

@JobaDiniz
Copy link
Author

@nateabele can you elaborate? Is there any docs on this new implementation?

@nateabele
Copy link
Contributor

Is there any docs on this new implementation?

Not yet. The code isn't even finished.

@JobaDiniz
Copy link
Author

Okay, looking forward to it 😄

@wbreza
Copy link

wbreza commented Apr 20, 2015

+1

@j-walker23
Copy link

This will remove so much garbage from my app around reloadOnSearch and $state.reload not working. Thanks so much. Can't wait.

I know it hasn't been long but i am anxious to tear out all my crap code. Any update on time?
As always, thanks for the awesome tool!

@nateabele
Copy link
Contributor

Working on it this week.

@ptrussart
Copy link

Hello @nateabele , did you make some progress on that topic ?

@j-hogue
Copy link

j-hogue commented May 14, 2015

My workaround for this issue

$state.current.reloadOnSearch = true;
$state.go($state.current, {year:  date.year(), month: date.month() + 1, day: date.date(), filter: 'day'}).then(function(){
     $state.current.reloadOnSearch = false;
 });

@j-walker23
Copy link

To anyone who sees this. My app is littered with garbage with work arounds which have evolved into worse workarounds because of this. What @j-hogue put is the idea i wish i had last year. Could have saved so much pain.

Mine is a little different, but this seriously works, so much better then anything i have seen anyone post as a work around. And its simple.

    hackLocation: (key, value) ->
        $state.current.reloadOnSearch = false
        $location.search key, value
        $timeout ->
            $state.current.reloadOnSearch = undefined

@eddiemonge eddiemonge added the bug label May 15, 2015
@christopherthielen christopherthielen modified the milestones: 0.2.14, 0.2.15 May 19, 2015
@christopherthielen
Copy link
Contributor

Hi all, this should be fixed for 0.2.15. Sorry for how long this bug has stood. Huge props to @metamatt for the analysis and PR #1962.
Dupe #1079

@christopherthielen
Copy link
Contributor

@JobaDiniz thanks for the plunker. Here is your plunk updated to 0.2.15 code showing reloadOnSearch:
http://plnkr.co/edit/5OPoKUDnn98JiKFlyEYL?p=preview

@JobaDiniz
Copy link
Author

Hi @christopherthielen
I updated the plunker because it was not working... now it does (http://plnkr.co/edit/AUuOb3iDxrx75q7tBu0Q?p=preview)

cheers!

@JobaDiniz
Copy link
Author

Big thanks! I've tested in my project and it works perfectly. 👏

@j-walker23
Copy link

@christopherthielen you guys are kings! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests