Skip to content

API Reference


API Reference / @dasch-ng/utils / src / provideValue

Function: provideValue() ​

provideValue<T>(provide, useValue, multi?): ValueProvider

Defined in: libs/ng/utils/src/lib/provide-helpers.ts:57

Creates a type-safe value provider for Angular dependency injection.

This helper ensures that the useValue matches the type of the injection token, preventing common type mismatches that can occur with plain provider objects.

Type Parameters ​

T ​

T

The type of the value to provide

Parameters ​

provide ​

InjectionToken<T> | Type<T>

The injection token or class to provide for

useValue ​

T

The value to inject (must match type T)

multi? ​

boolean

Optional flag to enable multi-provider (allows multiple values for the same token)

Returns ​

ValueProvider

A type-safe ValueProvider object

Example ​

typescript
import { InjectionToken } from '@angular/core';
import { provideValue } from '@dasch-ng/utils';

const API_URL = new InjectionToken<string>('API_URL');

// Type-safe: value must be a string
provideValue(API_URL, 'https://api.example.com');

// Type error: number is not assignable to string
// provideValue(API_URL, 123);

See ​

https://angular.dev/guide/di/dependency-injection-providers

Released under the MIT License.