gpt4 book ai didi

javascript - 根据angularjs中的url更改body类

转载 作者:行者123 更新时间:2023-11-30 08:34:51 25 4
gpt4 key购买 nike

这是我的网址

登录 - http://localhost/ang/#/login

对于仪表板 - http://localhost/ang/#/dashboard

这是我的正文标签的 html

如果当前 url 是 http://localhost/ang/#/login 那么正文应该有 class="login-layout" 标签,即,

<body ng-cloak="" class="login-layout>

否则应该有

<body ng-cloak="" class="no-skin">

我试图在 php 中执行此操作,但我无法在 # like said here 之后获取 url

AngularJS 本身可以做到这一点吗?

更新:

我试图在 AngularJS 中做到这一点

我可以从 Controller 获取 #

之后的 url
var nextUrl = next.$$route.originalPath;                   

但是我怎样才能更改类名..

最佳答案

我就是这样

<body class="{{currentclass}}" ng-cloak>

现在在登录 Controller 中做

$rootScope.currentclass = "login-layout";

在所有其他 Controller 中就这样做

$rootScope.currentclass = "no-skin";

在 app.run 中检查登录路径。

app.run(function($rootScope, $location){
rootScope.$on('$routeChangeStart', function(event, next, current){
if ($location.path() == '/login') {
$rootScope.currentclass = "login-layout";
}
else{
$rootScope.currentclass = "no-skin";
}
});

关于javascript - 根据angularjs中的url更改body类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32538270/

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