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

Cycle

The ThemeCycleService allows you to implement a button that sequentially advances through all configured themes.

Inject the service and use the cycle() method to move to the next theme.

import { Component, inject } from "@angular/core";
import { ThemeCycleService } from "ngx-theme-stack";
@Component({
selector: "app-theme-cycle",
template: `
<button (click)="theme.cycle()">
🔄 Cycle Theme
</button>
`,
})
export class ThemeCycle {
protected readonly theme = inject(ThemeCycleService);
}

The ThemeCycleService exposes several useful signals for building reactive interfaces:

Signal / PropTypeDescription
availableThemesstring[]Array containing all themes configured for the cycle.
selectedThemeSignal<NgTheme>The theme chosen by the user (can be 'system').
resolvedThemeSignal<NgTheme>The actual theme applied (never 'system').
cycleIndexSignal<number>The index of the current theme within the theme array.
precedingSignal<NgTheme>The previous theme in the cycle.
upcomingSignal<NgTheme>The next theme in the cycle (the one applied when calling cycle()).
isDarkSignal<boolean>true if the resolved theme is dark.
isLightSignal<boolean>true if the resolved theme is light.
isSystemSignal<boolean>true if the user has chosen the system preference.
isHydratedSignal<boolean>true after client-side hydration.
  • cycle(): Advances to the theme defined in upcoming().

For more details, see the ThemeCycleService API Reference.