简体   繁体   English

如何在AngularJs中向未登录的用户隐藏一些URL(页面)?

[英]How to hide some URL (pages) to a not logged user in AngularJs?

我将要创建一个显示广告的简单网站(以学习Angularjs v1),并且我只希望向公众显示2个页面:1)带有广告的页面2)和登录页面当用户登录时(管理员),他可以看到其他页面,例如createAd.html。

You could store this data in a cookie and read the cookie whether the user is logged in. And when the users logs out, of course destroy the cookie. 您可以将此数据存储在cookie中,无论用户是否登录,都可以读取cookie。当用户注销时,当然要销毁cookie。

Another option would be to store it in a variable in a global service and just have a get in the service to retrieve the value of the cookie. 另一种选择是将其存储在全局服务的变量中,而只需在服务中获取以获取cookie的值。

If using a factory you could simply use: 如果使用工厂,则可以简单地使用:

        factory.getAuthToken = function () {
            return _authToken;
        };

If you use an authentication token. 如果使用身份验证令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM