gpt4 book ai didi

javascript - Angular View ,如果未经身份验证,则显示单个 View

转载 作者:行者123 更新时间:2023-12-03 11:33:28 24 4
gpt4 key购买 nike

我正在使用wrapbootstrap 中的SmartAdmin 主题。我添加了大量自己的 Angular 代码 ~5k loc。

到目前为止,我已经使用主题的方法来查看渲染,但是,现在它成了一个问题,我需要一种方法来解决登录页面的问题。

项目的文件结构

project/
assets/
js/
app/
feature1/
controller.js
directive.js
filter.js
views/
feature1/
template.html
feature2/
index.html

当用户第一次进入项目根目录时,index.html已送达。里面index.html有各种ng-includes用于页眉、侧面导航和页脚。

我在每个请求之间使用基于 JWT 的身份验证和授权,如果用户未经过身份验证或超时,它将重定向到 /login通过$location.path('/login');

问题是它仍然显示页眉、侧面导航和页脚(来自 project/index.html )。无论如何,有没有办法解决这个问题,并让它只使用 index.html如果经过身份验证?

正如您所料,我不希望用户在未经身份验证时看到页眉/侧导航/页脚。不管templateUrl我在路由器中指定 index.html服务完毕,templateUrl在其内部使用。我需要这种情况不要只发生在特定路线上。

编辑:

我使用的模板是通过 <div ng-view></div> 插入的在 index.html .

index.html 的模拟布局:

<html ng-app="app">
<head>
</head>
<body ng-controller="PageCtrl">
<header ng-include="'templates/header.html'"></header>
<aside ng-controller="'templates/left-panel.html'"></aside>
<div ng-view></div>
<footer ng-include="'templates/footer.html'"></footer>
</body>
</html>

ng-view 的内部每个模板都有一个 Controller 。

最佳答案

在处理应用程序安全问题时,使用 ng-if 更加安全可靠。 ng-show 和 ng-hide 可以工作,但这只能设置/重置经过身份验证的标题和菜单的可见性。

因此,通过在脚本部分进行身份验证时设置类似 $scope.authenticated = true; 的范围变量,并在模板中使用该变量,如 ng-if="authenticated “

关于javascript - Angular View ,如果未经身份验证,则显示单个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26637512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com