provide
Generic types: | T U |
Type-safe factory function for producing NON-multi
configs.
See Also
Presentation
function provide (config : ProvideConfig <T, U>): Provider ;
Returns
Parameters
Name | Type | Description |
---|---|---|
config |
| type-safe configuration object |
Example usage
provide ({ token: TitleStrategy , useClass: AppTitleStrategy });
provide ({ token: TitleStrategy , useExisting: AppTitleStrategy });
// `AppTitleStrategy` have to be assignable to `TitleStrategy `.
declare const SNACKBAR_CONFIG: InjectionToken <SnackbarConfig>;
provide ({ token: SNACKBAR_CONFIG, useValue: { ... } });
// Type of `useValue` is inferred as `SnackbarConfig`, enabling autocomplete.
declare const BREAKPOINTS: InjectionToken <BreakpointMap >
provide ({ token: BREAKPOINTS, useFactory: (observer = inject (BreakpointObserver)) => observer.observe() });
// Return type of the factory has to match `BreakpointMap `
provide ({ token: APP_INITIALIZER , useFactory: () => () => {} });
// Type error. APP_INITIALIZER should be an array of functions, but the return type of the factory is a single function.
// Type '() => void' is not assignable to type 'readonly (() => void | Observable <unknown> | Promise<unknown>)[]'