- npm install primeng primeicons
"styles": [
"src/styles.css",
"node_modules/primeicons/primeicons.css",
"node_modules/primeflex/primeflex.css",
"node_modules/primeng/resources/primeng.min.css",
]
- lara-dark-blue
- lara-light-blue
- theme-lara-dark-blue.scss
- theme-lara-light-blue.scss
- @import "primeng/resources/themes/lara-dark-blue/theme.css";
- @import "primeng/resources/themes/lara-light-blue/theme.css";
{
"input": "src/theme-lara-light-blue.scss",
"bundleName": "lara-light",
"inject": false
},
{
"input": "src/theme-lara-dark-blue.scss",
"bundleName": "lara-dark",
"inject": false
}
"styles": [
"src/styles.css",
"node_modules/primeicons/primeicons.css",
"node_modules/primeflex/primeflex.css",
"node_modules/primeng/resources/primeng.min.css",
{
"input": "src/theme-lara-light-blue.scss",
"bundleName": "lara-light",
"inject": false
},
{
"input": "src/theme-lara-dark-blue.scss",
"bundleName": "lara-dark",
"inject": false
}
]
Dentro de la carpeta /app agregamos un servicio llamado theme.service.ts que tendra el siguiente código
import { Inject, Injectable } from '@angular/core';
import { DOCUMENT } from '@angular/common';
@Injectable({
providedIn: 'root',
})
export class ThemeService {
constructor(@Inject(DOCUMENT) private document: Document) {}
switchTheme(theme: string) {
let themeLink = this.document.getElementById('app-theme') as HTMLLinkElement;
if (themeLink) {
themeLink.href = theme + '.css';
}
}
}
<link id="app-theme" rel="stylesheet" type="text/css" href="lara-dark.css">
changeTheme(theme: string) {
this.themeService.switchTheme(theme);
}
<p-button (click)="changeTheme('lara-light')" class="mr-3 cursor-pointer">
light</p-button>
<p-button (click)="changeTheme('lara-dark')" class="mr-3 cursor-pointer">
dark</p-button>
En el mismo archivo he usado un MenuBar donde agrego los botones para cambiar de modo dia/noche puedes revisarlo
ng serve