Para tener temas Bootswatch en lugar del tema por defecto sólo tiene que sustituir el css bootstrap con el css del tema bootswatch. Sin embargo, si desea un conmutador de tema fresco para cambiar entre los temas de Bootswatch dinámicamente, a continuación, siga esta sugerencia.
Nota: reemplace ‘pscApp’ con el nombre generado de su aplicación.
Agrege los siguientes ficheros:
Controlador
Agrega el siguiente controlador como bootswatch.controller.js bajo la ruta webapp/app/components/bootswatch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ( function () { 'use strict' ; angular .module( 'pscApp' ) .controller( 'BootswatchController' , BootswatchController); BootswatchController.$inject = [ '$scope' , 'BootSwatchService' ]; function BootswatchController ($scope, BootSwatchService) { /*Get the list of availabel bootswatch themes*/ BootSwatchService.get().then( function (themes) { $scope.themes = themes.themes; $scope.themes.unshift({name: 'Default' ,css: '' }); //$scope.themes.push({name:'Default',css:''}); }); } })(); |
Servicio
Agrega el siguiente servicio como bootswatch.service.js bajo la ruta webapp/app/components/bootswatch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ( function () { 'use strict' ; angular .module( 'pscApp' ) .factory( 'BootSwatchService' , BootSwatchService); BootSwatchService.$inject = [ '$http' ]; function BootSwatchService ($http) { return { get: function () { return data.themes; } ); } }; } })(); |
Directiva
Agrega la siguiente directiva como bootswatch.directive.js bajo la ruta webapp/app/components/bootswatch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ( function () { 'use strict' ; angular .module( 'pscApp' ) .directive( 'jhSwitchTheme' , jhSwitchTheme); function jhSwitchTheme () { /*Directive binds to anchor to update the bootswatch theme selected*/ return { restrict: 'A' , scope: { theme : '=jhSwitchTheme' }, link: function (scope, element, attrs) { var currentTheme = $( "#bootswatch-css" ).attr( 'title' ); if (scope.theme.name === currentTheme){ element.parent().addClass( "active" ); } element.on( 'click' , function (){ $( "#bootswatch-css" ).attr( "href" , scope.theme.css); $( ".theme-link" ).removeClass( "active" ); element.parent().addClass( "active" ); }); } }; } })(); |
En el index.html:
Agregue lo siguiente al archivo index.html después de la tarea de construcción CSS vendor.css para que éstas no se minifiquen y compacten por tarea de compilación.
Añada en el header
1 2 3 4 5 6 7 8 9 10 11 | <!-- build:css content/css/vendor.css --> <!-- bower:css --> ... <!-- endinject --> <!-- endbuild --> <!-- placeholder link to load bootswatch themes, title holds the current applied theme name--> < link href = "" id = "bootswatch-css" rel = "stylesheet" title = "Default" > <!-- build:css assets/styles/main.css --> <!-- build:css content/css/main.css --> < link href = "content/css/main.css" rel = "stylesheet" > |
Añada lo siguiente en el pie de página
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | < div class = "footer" ng-cloak = "" > < div data-translate = "footer" > This is your footer</ div > <!-- Bottom demo to change themes --> < div class = "btn-group dropup" is-open = "status.isopen" ng-controller = "BootswatchController" uib-dropdown = "" > < button class = "btn btn-primary" id = "single-button" ng-disabled = "disabled" type = "button" uib-dropdown-toggle = "" > < span class = "glyphicon glyphicon-adjust" ></ span > < span class = "hidden-tablet" data-translate = "global.menu.theme" >Theme</ span > < span class = "caret" ></ span > </ button > < ul aria-labelledby = "single-button" class = "dropdown-menu" role = "menu" uib-dropdown-menu = "" > < li class = "theme-link" ng-repeat = "theme in themes" role = "menuitem" > < a href = "https://www.blogger.com/blogger.g?blogID=71686701309924355#" jh-switch-theme = "theme" >{{theme.name}}</ a > </ li > </ ul > </ div > </ div > |
Agrege los siguientes script tags en el fichero index.html manualmente. Si ‘gulp inject’ falla, recibirá errores de angular
1 2 3 4 | <!-- endinject --> <script src="app/components/bootswatch/bootswatch.controller.js"> </script> <script src="app/components/bootswatch/bootswatch.directive.js"> </script> <script src="app/components/bootswatch/bootswatch.service.js"> </script> |