[AngularJS] Default Child state and nav between child state
Let's say we want a parent state which is a abstract state. Two children states, one is for sinlge account view and another is for multi-accounts view.
By default, we want to go single account view:
.state('selfcare.my-services', {
url: 'my-services',
abstract: true,
resolve: {
authenticate: authenticate
}
})
.state('selfcare.my-services.single', {
url: '',
views: {
'main@': {
template: '<clm-my-services></clm-my-services>'
}
},
resolve: {
router: ($q, UserService) => {
let loginName = UserService.userProfileDataFromJWT.loginName;
return UserService.getServiceDetails(loginName)
.then((res) => {
if (_.size(res.billAccounts) > 1) {
return $q.reject('TO_MULTI_SERVICES');
} else {
return $q.when();
}
});
}
}
})
The idea is:
- Keep the default child state's url empty, so it knows this child state is default one, it will have the same url as parent.
- Make parent state as abstract state.
- authenticate is only need for parent, because it always goes from parent to children, so if parent is authenticated then it means child state is also authenticated.
Then in the code we have:router resolve block, you can name it anything you want:
router: ($q, UserService) => {
let loginName = UserService.userProfileDataFromJWT.loginName;
return UserService.getServiceDetails(loginName)
.then((res) => {
if (_.size(res.billAccounts) > 1) {
return $q.reject('TO_MULTI_SERVICES');
} else {
return $q.when();
}
});
It says that if there is multi service accounts then go multi-service account. So reject the promise, it will be handled by $stateChangeError.
$stateChangeError:
$rootScope.$on('$stateChangeError', function (event, toState, toParams, fromState, fromParams, error) {
switch (error) {case 'TO_SINGLE_SERVICE':
return $state.go('selfcare.my-services.single');
case 'TO_MULTI_SERVICES':
return $state.go('selfcare.my-services.compsite');
default:
$state.go('login.main');
} $('.progress-bar')
.hide();
});
The same as to handle multi-account view. And because you cannot access abstract directly by url, so to access the account, you need to do:
ui-sref="selfcare.my-services.single"
[AngularJS] Default Child state and nav between child state的更多相关文章
- Unable to make the session state request to the session state server处理
Server Error in '/' Application. Unable to make the session state request to the session state serve ...
- 在IIS上发布项目后浏览时报的错:Unable to make the session state request to the session state server
错误描述: Unable to make the session state request to the session state server. Please ensure that the A ...
- Unable to make the session state request to the session state server处理方法
Server Error in '/' Application. Unable to make the session state request to the session state serve ...
- 关于props和state以及redux中的state
React的数据模型分为共有数据和私有数据,共有数据可以在组件间进行传递,私有数据为当前组件私有.共有数据在React中使用props对象来调用,它包含标签所有的属性名称和属性值,props对象有三个 ...
- Ext.state.Manager.setProvider(new Ext.state.CookieProvider())
Ext.state.Manager.setProvider(new Ext.state.CookieProvider()) 初始化Ext状态管理器,在Cookie中记录用户的操作状态,如果不启用,象刷 ...
- 转: 解决【Unable to make the session state request to the session state server】
错误描述: Unable to make the session state request to the session state server. Please ensure that the A ...
- File(File f, String child) File(String parent, String child)
(转载)File(File f, String child) 根据f 抽象路径名和 child 路径名字符串创建一个新 File 实例. f抽象路径名用于表示目录,child 路径名字符串用于表示目录 ...
- [Functional Programming + React] Provide a reasonable default value for mapStateToProps in case initial state is undefined
For example we have a component, it needs to call 'react-redux' connect function. import { compose, ...
- Part 28 AngularJS default route
At the moment the problem is that, if you try to navigate to a route that is not configured, you wil ...
随机推荐
- 设置服务器远程连接mysql
一直单人开发所以没有考虑过这方面,到新公司要做合作开发,所以要进行设置,然后开始自己搞 下面把过程罗列一下: 1)由于使用的云服务器 ,所以上面都配置好了,直接配置了mysql的命令行输入密码就可以进 ...
- 数据库基本概念-oracle介绍
甲骨文公司,全称甲骨文股份有限公司是全球最大的企业软件公司,总部位于美国加利福尼亚州的红木滩.甲骨文是继Microsoft及IBM后,全球收入第三多的软件公司.甲骨文公司1989年正式进入中国市场.重 ...
- sizeof()用法
参考:sizeof_百度百科 sizeof()用法汇总(经典) 声明:本文是笔者抽出对自己有用的细节,对前两文的总结. 1.sizeof概念 sizeof是C语言中判断数据类型或者表达式长度符:不是一 ...
- BASLER 镜头选型白皮书
本文翻译自Basler镜头选型白皮书 有许多方法来进行镜头选型.本文将会讨论其中的指导原则,以帮助你在项目中选择合适的镜头.我们将讨论许多镜头的基本概念,比如镜头接口.图像大小.放大率.焦距.F数和光 ...
- matlab函数之diag
diag(A) 这个看似简单的函数确认让我头疼了几个小时 该函数其实有两个作用 ① 如果A是一个矩阵,那么diag(A)的作用便是提取A的对角线元素 ② 如果A是一个向量,那么diag(A)的作用便是 ...
- Maven镜像配置
镜像是为了提供更快的服务 如图:X就认为是Y的一个镜像. 编辑settings.xml配置中央仓库镜像: <settings> ... <mirrors> <mirror ...
- BZOJ 1237 配对
Description 你有\(n\)个整数\(A_{i}\)和\(n\)个整数\(B_{i}\).你需要把它们配对,即每个\(A_{i}\)恰好对应一 个\(Bp_{i}\).要求所有配对的整数差的 ...
- Struts2 全局拦截器、result 的实现
定义一个可以继承的包,在这个包里面写入自己常用的拦截器,于是就实现了全局拦截器的实现. 现在,我们定义一个专门用来继承的包: <!--专门提供前台继承的包--> <package n ...
- 字符串模式匹配算法——BM、Horspool、Sunday、KMP、KR、AC算法一网打尽
字符串模式匹配算法——BM.Horspool.Sunday.KMP.KR.AC算法一网打尽 本文内容框架: §1 Boyer-Moore算法 §2 Horspool算法 §3 Sunday算法 §4 ...
- 关于下拉刷新你是否真的非常理解还是只会搬砖?附 Android 实例子源代码文件下载地址380个合集
1,推荐几篇非常有用的博文 原创写的真的非常好 主要讲解原理,整体布局三部分组成以及设置padding等等作用, 下拉的具体实现 滑动到底部具体加载以及判断手势事件,再次推荐作者的 详细讲解 建议先看 ...