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

Child state with stateParams will load controller twice even if reloadOnSearch is false #2272

Closed
shavo007 opened this issue Sep 29, 2015 · 3 comments
Labels
Milestone

Comments

@shavo007
Copy link

Hi all,

I have seen a related bug here #125

Version of ui-router Im using is "angular-ui-router": "~0.2.15"

Issue is I have two child states with the same url as the parent. When i transition, I want the url updated but i dont want the controller called twice.

I added in the flag reloadOnSearch: false but still does not work.


  .state(STATES.PARENT, {
        url: '/track?id"',
        templateUrl: 'search/search.html',
        controller:'trackSearchController',
        controllerAs: 'trackSearchCtrl'
      })
      .state(STATES.SINGLE_ARTICLE_RESULTS, {
        templateUrl: 'results/results.html',
        reloadOnSearch: false,
        controller:'trackResultsController',
        controllerAs: 'trackResultsCtrl'
      })
      .state(STATES.MULTI_RESULTS, {
        templateUrl: 'results/multi/multi.results.html',
        reloadOnSearch: false,
        controller:'trackResultsController',
        controllerAs: 'trackResultsCtrl'
      })

So in the search controller, I transition to either single article or multi based on certain business rules.

Search controller:

if(blah){
   $state.go(STATES.SINGLE_ARTICLE_RESULTS);
   $location.search({'id': trackSearchCtrl.trackingId});
} else {
 $state.go(STATES.MULTI_RESULTS);
  $location.search({'id': trackSearchCtrl.trackingId});
}

Whats happening is if i search with a different input and the url updates, it calls the parent controller twice.

Any clue?

I attempted a plunker but does not work exactly as i had planned but has the same layout!

http://plnkr.co/edit/VLLGXZ?p=preview

All I want to achieve is to transition to the new state and update the url.

Thanks,
Shane.

@shavo007
Copy link
Author

i have created a new plunker:
http://plnkr.co/edit/MXZaml?p=preview

i took this from @christopherthielen plunker on reloadOnSearch.

Effectively, if i have two child states that share the same url as their parent, and update the url param the parent controller is called twice.

This is a major bug. The app i have to work on needs to be AA compliant. On JAWS screen reader, it is reading out the uncompiled template caused by this issue. Even with ng-cloak it still does not work.

This was all working seamlessly before i introduced browser navigation and updating url with each state transition.

@christopherthielen
Copy link
Contributor

Targeting post 1.0

@christopherthielen christopherthielen added this to the 1.5.0 milestone Jan 23, 2016
@stale
Copy link

stale bot commented Jan 24, 2020

This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues
may be reopened.

Thank you for your contributions.

@stale stale bot added the stale label Jan 24, 2020
@stale stale bot closed this as completed Feb 7, 2020
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

2 participants