To implement themes in application I create multiple css files with different styles like (red, green,blue).
Red.css
- body
- {
- font-family: "Source Sans Pro",Calibri,Candara,Arial,sans-serif;
- font-size: 15px;
- line-height: 1.42857143;
- color: #333333;
- background-color: red;
- }
- body
- {
- font-family: "Source Sans Pro",Calibri,Candara,Arial,sans-serif;
- font-size: 15px;
- line-height: 1.42857143;
- color: wheat;
- background-color: blue;
- }
- body
- {
- font-family: "Source Sans Pro",Calibri,Candara,Arial,sans-serif;
- font-size: 15px;
- line-height: 1.42857143;
- color: chartreuse;
- background-color: green;
- }
- angular.module('ThemeApp', [])
- .controller('mainController', function ($scope) {
- // set the default theme
- $scope.css = 'Red';
- // create the list of themes
- $scope.bootstraps = [
- { name: 'Red', url: 'Red' },
- { name: 'Blue', url: 'Blue' },
- { name: 'Green', url: 'Green' }
- ];
- });
Now, moving to HTML Page.
- <html ng-app="ThemeApp" ng-controller="mainController">
- <head>
- <script src="Scripts/angular.min.js"></script>
- <!-- pull in css based on angular -->
- <link rel="stylesheet" ng-href="{{css}}.css">
- <!-- bring in JS and angular -->
- <script src="CustomJS/app.js"></script>
- </head>
- <body>
- <div >
- <form>
- <div >
- <h1> <label>Select Theme</label></h1>
- <select ng-model="css" ng-options="bootstrap.url as bootstrap.name for bootstrap in bootstraps">
- </select>
- </div>
- </form>
- </div>
- </body>
- </html>


So, We can exactly see how it works. We are pulling our own custom css file dynamically with ng-Href directive in AngularJS.

Pratap GayenPosted May 26, 2017, 1:37 PM
Can u please provide the source code