UtilAdded in v15Optional

wrFeature

Builds a provideWr() feature: what every withX() function returns. For a library that adds its own app-wide setting.

Usage

Name the feature and list what it provides. The app passes the result to provideWr() with the built-in features.

import { InjectionToken } from '@angular/core';
import { type WrFeature, wrFeature } from 'ngwr/utils';

export interface MapsOptions {
  readonly tiles?: string;
}

export const MAPS_OPTIONS = new InjectionToken<MapsOptions>('MAPS_OPTIONS', {
  providedIn: 'root',
  factory: () => ({}),
});

export function withMaps(options: MapsOptions = {}): WrFeature<'maps'> {
  return wrFeature('maps', [{ provide: MAPS_OPTIONS, useValue: options }]);
}
import { provideWr } from 'ngwr';
import { withDensity } from 'ngwr/density';

providers: [provideWr(withDensity({ defaultDensity: 'sm' }), withMaps({ tiles: '/tiles' }))],
ArgumentWhat it is
kind The feature's name. In dev mode provideWr() throws when it gets the same kind twice, so pick one no other feature uses.
providersWhat the feature registers. provideWr() flattens them into its own providers.
  • Give the token a root default, so the setting is optional.
  • Annotate the return type as WrFeature<'kind'>. Do not read the object's members: they are private.

API

NameDescriptionTypeDefault
wrFeature(kind, providers)Builds the feature provideWr() takes.<K extends string>(kind: K, providers: readonly (Provider | EnvironmentProviders)[]) => WrFeature<K>-
WrFeature<K>One piece of app-wide configuration. The return type of a withX() function.interface-

See also