withThemeBuilder
Generic types: | Builder |
Creates a token generation specification, which specifies the target
and relevant configurations to be passed to the builder.
See Also
Presentation
function withThemeBuilder (
name: string,
builder: ProviderToken <Builder>,
config :
| ThemeBuilderConfigOf <Builder>
| Observable <ThemeBuilderConfigOf <Builder>>,
): Observable <ThemeBuilderComposition >;
Returns
Parameters
Name | Type | Description |
---|---|---|
name | string | The name that will be passed to the theme builder. |
builder |
| The token that can be used to retrieve the theme builder |
config |
| The configuration object that will be passed to the theme builder. |
Usage Notes
A builder class can be passed to the builder
parameter because constructor classes are valid tokens for dependency injection. It is worthy noting that you need to make sure that there is a provider for the token. This function does not register providers for the token.
provide ({ token: ColorBuilder, useClass: MyColorBuilder }),
withThemeBuilder ('color', ColorBuilder, { primaryColor: PRIMARY_COLOR }),
An observable can be passed as the
parameter, in which case the theme is expected to be updated on every value emission.
withThemeBuilder (
'color',
ColorBuilder,
observePreferredColorScheme().pipe (
map ((isDark) => ({ primaryColor: PRIMARY_COLOR, dark: isDark })),
),
);
In order to gain access to the injection context, use the
RxJS operator, which defers the invocation of the observable factory until the observable is subscribed during the environment initialization, where an injection context is available.
withThemeBuilder (
'color',
ColorBuilder,
defer ((schemeObserver = inject (PreferredColorSchemeObserver)) =>
schemeObserver
.observe()
.pipe (map ((isDark) => ({ primaryColor: PRIMARY_COLOR, dark: isDark }))),
),
);