解决方式来源:https://stackoverflow.com/questions/25316591/angularjs-ui-router-state-reload-child-state-only/25322797#25322797

路由路径设置:structured.text   ;structured是第一层路由,text是第二层路由;

问题如下,当$state.transitionTo路由到第二层是,structured的controller也会执行一次,导致页面控件重新加载刷新。

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

查了github看到 https://github.com/angular-ui/ui-router/issues/1612,说此问题已经被fixed,然而设置了reload: stateObj并没有卵用。

I think this makes sense and is 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.

直到看到了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.go calls $state.transitionTointernally but automatically sets options to { location: true, inherit: true, relative: $state.$current, notify: true }. This allows you to easily use an 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. $state.go() is recommended in most situations.

$state.transitionTo是底层方法,用$state.go是用它实现的,$state.go设置了一些默认参数 ,于是用$state.go试了下,竟然成功;

debug看了下原来是默认options inherit:true和reload:false共同引发的问题:

错误写法1:

$state.transitionTo(
"structured.text",
{ args : $stateParams },
{ reload: true}
);

 原因:路由写了两级,structured的controller会被重复执行

错误写法2:

$state.transitionTo(
".text",
{ args : $stateParams },
{ reload: true}
);

 原因:relative没有设置和inherit默认又是false,报错路由找不到

正确写法:

$state.go(
'structured.text',
  {},
  { reload: 'structured.text'}
);

https://github.com/angular-ui/ui-router/issues/1612#issuecomment-77757224 这里作为一个bug被fixed,路由设计还是太蠢...

推荐使用$state.go, 用$state.transitionTo底层方法的话,options要都正确,问题解决,搞了半天研究这个破东西,api设计的让人郁闷。

Angularjs ui router,路由嵌套 父controller执行问题的更多相关文章

  1. [转]AngularJS+UI Router(1) 多步表单

    本文转自:https://www.zybuluo.com/dreamapplehappy/note/54448 多步表单的实现   在线demo演示地址https://rawgit.com/dream ...

  2. angularJS ui router 多视图单独刷新问题

    场景:视图层级如下 view1 --view11 --view111 需求:view11的一个动作过后,单独刷新view12 解决方式:修改层级设计 view1 --view11 --view111 ...

  3. angular ui.router 路由传参数

    angular已经用了一段时间了,最近在做路由,做一下笔记. 路由跳转的时候进行穿参 ui.router方式 <a ui-sref="edit({id:5})"> 编辑 ...

  4. angularjs中的路由介绍详解 ui-route(转)

    http://www.cnblogs.com/littlemonk/p/5500801.html 这篇文章主要介绍了Angularjs中UI Router全攻略,涉及到angularjs ui rou ...

  5. angularjs中的路由介绍详解 ui-route

    这篇文章主要介绍了Angularjs中UI Router全攻略,涉及到angularjs ui router的基本用法,需要的朋友参考下吧   首先给大家介绍angular-ui-router的基本用 ...

  6. AngularJS 使用 UI Router 实现表单向导

    Today we will be using AngularJS and the great UI Router and the Angular ngAnimate module to create ...

  7. [转]AngularJS 使用 UI Router 实现表单向导

    本文转自:http://www.oschina.net/translate/angularjs-multi-step-form-using-ui-router 今天我们将使用AngularJs和伟大的 ...

  8. [AngularJS] “多重路由”嵌套模块——AngularJS“路由”嵌套学习资料教程

    这是小编的一些学习资料,理论上只是为了自己以后学习需要的,但是还是需要认真对待的 以下内容仅供参考,请慎重使用学习 1.AngularJS路由嵌套 Angularjs本身自带路由模块,可以满足通过不同 ...

  9. angularjs ngRoute和ui.router对比

    ngRoute模块是angularjs自带的路由模块,ui.router是一个第三方路由模块,接下来将对两者进行一个对比: ng-router(angular-router.js) ng-view n ...

随机推荐

  1. Android按钮单击事件处理的几种方法(Android学习笔记)

    方法一:匿名内部类实现按钮事件处理 this.btnButton=(Button)super.findViewById(R.id.mybtn); this.btnButton.setOnClickLi ...

  2. mysql查询不区分大小写

    摘自:http://www.jb51.net/article/70884.htm 当我们输入不管大小写都能查询到数据,例如:输入 aaa 或者aaA ,AAA都能查询同样的结果,说明查询条件对大小写不 ...

  3. 解密QQ号

    啊哈~ ---------------------------------------------------------- http://bbs.ahalei.com/thread-4489-1-1 ...

  4. loj #108. 多项式乘法

    #108. 多项式乘法   题目描述 这是一道模板题. 输入两个多项式,输出这两个多项式的乘积. 输入格式 第一行两个整数 n nn 和 m mm,分别表示两个多项式的次数. 第二行 n+1 n + ...

  5. 【51nod1847】奇怪的数学题(Min_25筛+杜教筛)

    题面 传送门 题解 这题有毒--不知为啥的错误调了半天-- 令\(f(i)={sgcd(i)}\),那么容易看出\(f(i)\)就是\(i\)的次大质因子,用\(i\)除以它的最小质因子即可计算 于是 ...

  6. Orcale创建函数(function)

    Oraclec创建函数的语法规则 create or replace function  函数名 (参数名1 参数类型,参数名2 参数类型)  return number  is Result num ...

  7. TensorFlow车辆检测

    1.先在UIUC Image Database for Car Detection下载训练数据集. 下载地址:http://cogcomp.org/Data/Car/ 下载解压之后文件目录如图所示,这 ...

  8. Linux系统centos中sudo命令不能用----提升权限

    gyx is not in the sudoers file.  This incident will be reported. 1.切换到root用户 su ,如果想要切换回去 exit 2.添加s ...

  9. 解决maven项目中有小红叉的问题

    首先在window--perferences--showview中显示problems中查看出错的原因

  10. redis修改密码和更改端口

    Liunx下redis修改密码和更改端口 redis一个实例就是一个节点,每个节点分配一个端口号,每个节点对应一个redis.conf配置文件. redis默认配置的端口号是6379,假设现在要多配置 ...