在angularJS中的stateStateProvider上设置条件 [英] set condition on otherwise stateProvider in angularJS

查看:245
本文介绍了在angularJS中的stateStateProvider上设置条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个项目,一旦用户输入了他的ID,他将无法在使用该应用程序时再次看到登录页面.

I am working on a project and it needs once a user entered his ID he wont be able to see the login page again when he will use the app.

我无法理解该怎么做,而我尝试过的这种逻辑是行不通的.

I am not able to understand how to do this logic which I had tried is not working.

有人可以帮我吗.这是我在Google云端硬盘上的项目链接,可以看看:

can anyone help me on this.This is my link of project on google drive have a look:

https://drive.google.com/open?id=0B51wL8pUai8XSHc0eHFQQ1cxX2M

推荐答案

在这种情况下,您需要使用localStorage,一旦成功登录,将当前用户设置为true,而在注销时将该标志设置为false.

You need to use localStorage in this case, where once you successfully login set your current user to true and on logout set that flag to false.

在您的app.run块上,您可以设置条件.

and over your app.run block you can put a condition.

$rootScope.$on('$stateChangeStart', function (event, toState, toParams,fromState, fromParams) {
       if (toState.name !== 'login') {
            if (!localStorageService.get('currentUser') {
                event.preventDefault();
                $state.go('login');
            }
        } else {
            return false;
        }
}

这篇关于在angularJS中的stateStateProvider上设置条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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