实施角UI路由器懒议决 [英] Implementing Angular UI router lazy resolves

查看:107
本文介绍了实施角UI路由器懒议决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用角和放大器; UI路由器,我需要为我的父母州的议决之一是懒惰。

I use Angular & UI router and I need for one of my parent states's resolves to be lazy.

这样做的原因是,我有一个名为状态验证由子状态的整个层次继承。我需要一个名为 isAuthenticated 来懒洋洋地解决了决心(即每次输入了验证状态的孩子)。

The reason for this is that I have a state called authenticated that is inherited by a whole hierarchy of child states. I need the resolve called isAuthenticated to be resolved lazily (i.e. each time a child of the authenticated state is entered).

下面是我的父母验证状态:

    .state('authenticated', {
        abstract: true,
        parent: 'root',
        views: {
            'header@': {
                controller: 'NavbarCtrl',
                templateUrl: 'app/navbar/views/navbar.view.html'
            }
        },
        resolve: {
            currentMember: ['domainService', function (domainService) {
                return domainService.currentMember();
            }],
            isAuthenticated: ['$rootScope', '$q', '$cookies', function ($rootScope, $q, $cookies) {
                return ($rootScope.globals.authenticated && $cookies.globalsAuthenticated) || $q.reject({unAuthorized: true});
            }]
        }
    })

我想这样做,这样我也可以把未经授权的用户能够轻松的登录页面。

I want to do that so that I can redirect unauthenticated users to login page easily.

我怎样才能在使用目前实施的UI路由器的一个懒惰的决心( 0.2.15 )?

How can I have a lazy resolve using the current implementation of the UI router (0.2.15)?

P.S。的我看了一下 OC延迟加载但似乎是针对整个加载模块或文件。 ..

P.S. I had a look at oc lazy load but is appears to be aimed at loading whole modules or files...

推荐答案

您可以使用 stateChangeStart 它会帮你做你正在寻找确切的事情,检查此链接了

you can use stateChangeStart it will help you for doing the exact thing you are looking for , check this link out

<一个href=\"http://brewhouse.io/blog/2014/12/09/authentication-made-simple-in-single-page-angularjs-applications.html\" rel=\"nofollow\">http://brewhouse.io/blog/2014/12/09/authentication-made-simple-in-single-page-angularjs-applications.html

这篇关于实施角UI路由器懒议决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆