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

Select

The ThemeSelectService is ideal for dropdown menus where users can choose from all configured themes.

Inject the service and use availableThemes to list the options and select() to change the theme.

import { Component, inject } from "@angular/core";
import { ThemeSelectService } from "ngx-theme-stack";
@Component({
selector: "app-theme-select",
template: `
<select name="select-theme" (change)="onThemeChange($event)">
@for (t of this.theme.availableThemes; track t) {
<option [value]="t" [selected]="this.theme.selectedTheme() === t">
{{ t }}
</option>
}
</select>
`,
})
export class ThemeSelect {
protected readonly theme = inject(ThemeSelectService);
onThemeChange(event: Event) {
const value = (event.target as HTMLSelectElement).value;
this.theme.select(value);
}
}

The ThemeSelectService simplifies integration with selection components:

Signal / PropTypeDescription
availableThemesstring[]Array containing all configured themes.
selectedThemeSignal<NgTheme>The theme chosen by the user (can be 'system').
resolvedThemeSignal<NgTheme>The actual theme applied (never 'system').
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.
  • select(theme: NgTheme): Changes the active theme to the provided value.

For more details, see the ThemeSelectService API Reference.