Angularjs UI router, routing nested parent controller execution issues

Source: Internet
Author: User

Routing path settings: Structured.text; Structured is the first layer of routing, text is the second layer of routing;

The problem is that when $state.transitionto is routed to the second tier, the controller of structured is also executed once, causing the page control to reload refreshed.

$state. Transitionto (    "Structured.text",     {args: $stateParams},    {reload:false});

Checked GitHub to see https://github.com/angular-ui/ui-router/issues/1612, said the problem has been fixed, but set up reload:stateobj and no eggs.

Christopherthielen commented on 8 Mar 2015

I think this makes sense and was a good idea. I ' d like to omit the second reloadstate parameter, and overload the existing reload parameter.

  • { reload: true }Reloads all,
  • { reload: ‘foo.bar‘ }Reloads Top.bar, and any children
  • { reload: stateObj }Reloads state found in stateobj, and any children

Squash your commits and set your commit message to match the contributor guidelines. If @nateabeleconcurs, I think we ' ll merge this in.

Until I saw Https://stackoverflow.com/questions/21105528/difference-between-state-transitionto-and-state-go-in-angular-ui-router.

$state. Go (to [, Toparams] [, Options])

Returns a Promise representing the state of the transition.

Convenience method for transitioning to a new state. $state.gocalls $state.transitionTo internally but automatically sets options to { location: true, inherit: true, relative: $state.$current, notify: true } . This allows your to easily use a absolute or relative to path and specify only the parameters you ' d like to update (while Letting unspecified parameters inherit from the current state).

$state. Transitionto (To, toparams [, Options])

Returns a Promise representing the state of the transition.

Low-level method for transitioning to a new state. $state.go()uses transitionTo internally. is recommended in the most $state.go() situations.

$state. Transitionto is the underlying method, with $state. Go is implemented with it,$state. Go sets Some default parameters, so use the $state. Go tried, unexpectedly success;

Debug looked at the original default options inherit:true and Reload:false common problems raised:

Error notation 1:

$state. Transitionto (    "Structured.text",     {args: $stateParams},    {reload:false});    

Cause: The route is written in level two, and the structured controller will be executed repeatedly

Error notation 2:

$state. Transitionto (      ". Text",     {args: $stateParams},    {reload:false});   

Cause: Relative not set and inherit default is False

Correct wording:

$state. Transitionto (    ". Text",     {args: $stateParams},    {reload:false        inherit:true,        relative: " Structured "});    

Or

$state. Go (    ". Text",     {args: $stateParams},    false});    

Indeed recommended the use of $state.go, with the $state.transitionto bottom method, the options to be correct, problem solving, engaged in a half-day event, this API design let people depressed.

Angularjs UI router, routing nested parent controller execution issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.