0
我更改了<body>
元素上的類,具體取決於我的網站當前顯示哪個$state
。模板中不可見的角rootScope
我說<body class="{{specialClass}}">
,其中specialClass
是一個變量$rootScope
。這個變量被設置在我的主要應用模塊的run
塊:
angular.module("main", [dependencies])
.run(function($rootScope) {
$rootScope.$on('$stateChangeSuccess', function(event, currentState){
switch (currentState.name) {
case "about":
console.log("I'm on landing page, set specialClass in $rootScope");
$rootScope.specialClass = 'landing-page';
break;
default:
$rootScope.specialClass = '';
break;
}
})
});
出於某種原因,我的模板不看specialClass
變量,因此該類屬性爲空。與此同時,出現"I'm on landing page, set specialClass in $rootScope"
。
怎麼了?
我的全index.html
模板:
<html>
<head>
<base href="/">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My project</title>
</head>
<body ng-app="main" class="{{specialClass}}">
<ui-view>
This is my application.
</ui-view>
</body>
</html>
什麼是更瘋狂,當我與的WebPack開發服務器開發服務前端,它工作正常,類切換。但是當我用Django在生產中使用它時,事實並非如此。控制檯輸出在兩種情況下都存在。根據ngClass有關數組語法
嘗試使用納克級的指令 – Revive
中標記您的引導你的應用程序? ? 'ngApp'指令必須包含body標籤。 – Hitmands
該模板在哪裏? –