【发布时间】:2016-03-27 06:33:25
【问题描述】:
我有一个要求。你能提出实现它的可能方法吗?
我想根据每个路由中传递的 URL 更改我的应用程序的主题。我正在使用以下技术。 - 前端:Angular JS - 后端:Node.js
例如:localhost/x/about 本地主机/y/关于
我通过 cookie 在登录时使用 localtion.search 传递参数来实现这些。但是我在所有路线中都需要该主题参数。基于该主题需要更改。任何人都可以提出可能的方法。
app.js
app = angular.module('themeApp', ['ngRoute'])
app.config(function($routeProvider){
$routeProvider
.when('/',{
templateUrl: 'home.html'
})
.when('/:id/about',{
templateUrl: 'about.html'
})
.otherwise({
redirectTo: '/'
});
});
app.controller('themeController', function ($scope, $routeParams) {
console.log($routeParams.id);
// set the default theme
$scope.css = $routeParams.id;
});
menu.html(不完整,在此混淆,请指正,如何调用)
<li>
<a href="about">About</a>
</li>
<li>
<a href="home">Home</a>
</li>
index.html
<html ng-app="themeApp" ng-controller="themeController">
<head>
<!-- pull in css based on angular -->
<link rel="stylesheet" ng-href="css/{{css}}.css">
</head>
<body>
<div ng-view></div>
<!-- bring in JS and angular -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.14/angular.js"> </script>
<script rc="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.14/angular-route.js"></script>
<script src="app.js"> </script>
</body>
</html>
css/
it contains the three files,
- red.css
body{
background-color: red;
color: #333;
font-family: "Source Sans Pro",Calibri,Candara,Arial,sans-serif;
font-size: 15px;
}
- green.css
身体{
背景颜色:绿色; 颜色:#333; font-family: "Source Sans Pro",Calibri,Candara,Arial,sans-serif;
字体大小:15px; }- blue.css
身体{
背景颜色:蓝色; 颜色:#333; font-family: "Source Sans Pro",Calibri,Candara,Arial,sans-serif;
字体大小:15px; }
- blue.css
身体{
【问题讨论】:
标签: css angularjs node.js cookies themes