Skip to content

API Reference

ngx-theme-stack provides a powerful and flexible API designed around Angular Signals for maximum reactivity.

The brain of the library. It handles theme persistence, system preference detection, and DOM updates.

SignalTypeDescription
selectedThemeSignal<NgTheme>The theme explicitly selected by the user (can be 'system').
resolvedThemeSignal<NgTheme>The actual theme applied to the DOM (resolves 'system' to 'light' or 'dark').
isDarkSignal<boolean>True if the resolved theme is 'dark'.
isLightSignal<boolean>True if the resolved theme is 'light'.
isSystemSignal<boolean>True if the selected theme is 'system'.
isHydratedSignal<boolean>True after client-side hydration. Crucial for SSR.
  • setTheme(theme: NgTheme): void: Changes the active theme. Throws if the theme is invalid.

These services wrap CoreThemeService to provide common interaction patterns.

Ideal for simple “Dark/Light” switches.

  • toggle(): Toggles between 'dark' and 'light'. If current is 'system', it switches to the opposite of the current system preference.

Ideal for buttons that rotate through all available themes (e.g., System → Light → Dark → …).

  • cycle(): Advances to the next theme in the configured themes array.

provideThemeStack(config?: Partial<NgConfig>)

Section titled “provideThemeStack(config?: Partial<NgConfig>)”

Provider function to initialize the library in your app.config.ts.

OptionTypeDefaultDescription
defaultThemeNgTheme'system'Theme used on first visit.
storageKeystring'ngx-theme...-theme'Key for localStorage.
mode'class' | 'attribute' | 'both''class'How to apply theme to <html>.
strategy'blocking' | 'critters''critters'Anti-flash strategy.
themesNgTheme[]['light', 'dark', 'system']Supported themes.

A type-safe union of themes. By default, it accepts 'light' | 'dark' | 'system' and any string.

  • 'class': Adds the theme name as a class to <html>.
  • 'attribute': Sets data-theme="theme-name" on <html>.
  • 'both': Applies both.
  • 'blocking': Standard CSS strategy.
  • 'critters': Optimized for SSR/SSG (inlined styles).