Angularjs ui router,路由嵌套 父controller执行问题
路由路径设置: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并没有卵用。
christopherthielen commented on 8 Mar 2015
|
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.
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.gocalls$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()usestransitionTointernally.$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执行问题的更多相关文章
- [转]AngularJS+UI Router(1) 多步表单
本文转自:https://www.zybuluo.com/dreamapplehappy/note/54448 多步表单的实现 在线demo演示地址https://rawgit.com/dream ...
- angularJS ui router 多视图单独刷新问题
场景:视图层级如下 view1 --view11 --view111 需求:view11的一个动作过后,单独刷新view12 解决方式:修改层级设计 view1 --view11 --view111 ...
- angular ui.router 路由传参数
angular已经用了一段时间了,最近在做路由,做一下笔记. 路由跳转的时候进行穿参 ui.router方式 <a ui-sref="edit({id:5})"> 编辑 ...
- angularjs中的路由介绍详解 ui-route(转)
http://www.cnblogs.com/littlemonk/p/5500801.html 这篇文章主要介绍了Angularjs中UI Router全攻略,涉及到angularjs ui rou ...
- angularjs中的路由介绍详解 ui-route
这篇文章主要介绍了Angularjs中UI Router全攻略,涉及到angularjs ui router的基本用法,需要的朋友参考下吧 首先给大家介绍angular-ui-router的基本用 ...
- AngularJS 使用 UI Router 实现表单向导
Today we will be using AngularJS and the great UI Router and the Angular ngAnimate module to create ...
- [转]AngularJS 使用 UI Router 实现表单向导
本文转自:http://www.oschina.net/translate/angularjs-multi-step-form-using-ui-router 今天我们将使用AngularJs和伟大的 ...
- [AngularJS] “多重路由”嵌套模块——AngularJS“路由”嵌套学习资料教程
这是小编的一些学习资料,理论上只是为了自己以后学习需要的,但是还是需要认真对待的 以下内容仅供参考,请慎重使用学习 1.AngularJS路由嵌套 Angularjs本身自带路由模块,可以满足通过不同 ...
- angularjs ngRoute和ui.router对比
ngRoute模块是angularjs自带的路由模块,ui.router是一个第三方路由模块,接下来将对两者进行一个对比: ng-router(angular-router.js) ng-view n ...
随机推荐
- Django之博客系统:增加评论
3既然是博客,那肯定就有留言评论系统.在这一章就来建立一个评论系统. 1 创建一个模型来保存评论 2 创建一个表单来提交评论并且验证输入的数据 3 添加一个视图函数来处理表单和保存新的评论到数据库 4 ...
- ubuntu - 常用问题解决命令
查看本机网络通畅 - 网络是否可连接(远程链接时,检验防火墙) ping -c 10 localhost 查看本机进程/端口占用情况(看某一进程是否开启) netstat -tln 具体查看某一进程 ...
- sqlplus能登录但查询数据报ORA-00942: 表或视图不存在
在表名前加表所属的用户就能查了: SELECT * FROM ABC.TABLENAME;(ABC是表的OWNER)
- Liunx基础优化配置
1: 为系统添加操作用户,并授予sudo权限 [root@localhost ~]# groupadd cai [root@localhost ~]# useradd cai -g cai [roo ...
- Python列表删除的三种方法
1.使用del语句删除元素 >>> i1 = ["a",'b','c','d'] >>> del i1[0] >>> prin ...
- java读取 500M 以上文件,java读取大文件
java 读取txt,java读取大文件 设置缓存大小BUFFER_SIZE ,Config.tempdatafile是文件地址 来源博客http://yijianfengvip.blog.163.c ...
- 「FJ2014集训」采药人的路径
啦啦啦 来写一篇题解 洛谷链接: P4930 「FJ2014集训」采药人的路径 统计路径?嗯往点分治上想. 把0和1转化为-1和1,求和完dis为0的路径就是阴阳平衡的路径了. 如果题目没有限制要有中 ...
- DP【洛谷P3089】 [USACO13NOV]POGO的牛Pogo-Cow
[洛谷P3089] [USACO13NOV]POGO的牛Pogo-Cow FJ给奶牛贝西的脚安装上了弹簧,使它可以在农场里快速地跳跃,但是它还没有学会如何降低速度. FJ觉得让贝西在一条直线的一维线路 ...
- <aop:aspectj-autoproxy proxy-target-class="false"/>导致出现404状态码
今天干活的时候,由于是一个web应用,想在每次发送请求和返回响应的时候记录日志,也就是代理Controller,想起了之前的spring AOP,于是按照之前的配置配置好了,可是发现每次前端发送请求都 ...
- spring boot中 启用aspectj
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...