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 ...
随机推荐
- 温故而知新_C语言_递归
递归. 是的,差不多就是这种感觉.上面就是类似递归的显示表现. 2017 10 24更新: 递归这个问题放了很久.也没有写.大概是自己还没有好好理解吧. 在这里写下自己理解的全部. 一 何为递归. 字 ...
- EasyUi取消选中表格的所有行
- 安卓手机牛逼软件Termux中安装Archlinux,安装Jdk
说出来你可能不信,手机上居然装了两个linux系统,和真实的linux有些许些差别. 首先安装了Termux以后你发现,好多linux常用功能都有,什么Pyhton,gcc,g++,ruby,Php, ...
- ASP.NET-GridView之导出excel或word
在CS阶段我们涉及到表格的导出,再Web开发同样可以实现,而且实现形式多种多样.以下面的例子说明表格导出到excel和word 这里用到了一个后台方法输出流形成***文件的的公共方法 DEMO < ...
- 新姿势!Redis中调用Lua脚本以实现原子性操作
背景:有一服务提供者Leader,有多个消息订阅者Workers.Leader是一个排队程序,维护了一个用户队列,当某个资源空闲下来并被分配至队列中的用户时,Leader会向订阅者推送消息(消息带有唯 ...
- Linq中DeferredLoadingEnabled,DataLoadOption的用法
1. 基本的数据关系图 Student和Class之间是多对一关系,Student和Course之间是多对多关系. DataContext的DeferredLoadingEnabled属性指定是否需 ...
- sql 日期对比
来自这里
- windows_study_2
描述:如何确定像%ProgramFiles%这样格式的目录的具体位置? 解决:运行——cmd——echo %ProgramFiles%——回车——界面就显示出目录位置了.
- 【bzoj2935】[Poi1999]原始生物
2935: [Poi1999]原始生物 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 145 Solved: 71[Submit][Status][D ...
- maven set MAVEN_OPTS
http://juvenshun.iteye.com/blog/240257 https://docs.alfresco.com/5.1/tasks/alfresco-sdk-install-mave ...