Skip to content
⭐ Loving ngx-theme-stack? Support us with a star on GitHub!

Custom

If the convenience services (Toggle, Select, Cycle) don’t fit your needs, you can use the CoreThemeService directly.

The CoreThemeService is the brain of ngx-theme-stack. It provides signals for the theme state and methods to change it manually.

import { Component, inject } from "@angular/core";
import { CoreThemeService } from "ngx-theme-stack";
@Component({
selector: "app-custom-theme",
template: `
<div [class.is-hydrated]="theme.isHydrated()">
<p>Current theme: {{ theme.resolvedTheme() }}</p>
<button (click)="theme.setTheme('dark')">Force Dark</button>
<button (click)="theme.setTheme('system')">Use System</button>
</div>
`,
})
export class CustomTheme {
protected readonly theme = inject(CoreThemeService);
}
Signal / PropDescription
availableThemesArray containing all configured themes.
selectedThemeThe theme chosen by the user (can be 'system').
resolvedThemeThe actual theme applied (never 'system').
isDarktrue if the resolved theme is dark.
isLighttrue if the resolved theme is light.
isSystemtrue if the user has chosen the system preference.
isHydratedtrue after client-side hydration.
  • setTheme(theme: NgTheme): Sets the active theme.

For a complete list of signals and methods, see the CoreThemeService API Reference.