Angular

Explain the purpose and usage of InjectionToken in Angular.

November 28, 2025

download ready
Thank You
Your submission has been received.
We will be in touch and contact you soon!

InjectionToken in Angular is used to create a unique identifier for a dependency that is not a class, such as a string, object, or interface. It enables type-safe dependency injection for values or complex objects that don’t have a runtime representation.

InjectionToken allows injecting non-class dependencies into Angular components or services by providing a token that Angular's DI system can recognize and resolve. It's especially useful for injecting configuration values or abstract types safely.

Code

import { InjectionToken, Inject } from '@angular/core';

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

@NgModule({
  providers: [{ provide: API_URL, useValue: 'https://api.example.com' }]
})
export class AppModule {}

@Component({})
export class MyComponent {
  constructor(@Inject(API_URL) private apiUrl: string) {
    console.log(this.apiUrl);
  }
}
Hire Now!

Need Help with Angular Development ?

Work with our skilled angular developers to accelerate your project and boost its performance.
**Hire now**Hire Now**Hire Now**Hire now**Hire now