Angular
Angular

Explain the purpose and usage of InjectionToken in Angular.

November 28, 2025

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 ?

Ready to leverage the power of conversational AI? Start your project with Zignuts expert AI developers.
bg-image
download-image
Company Deck
PDF, 3MB
© 2026 Zignuts Technolab. All Rights Reserved.
branch imagesbranch imagesbranch imagesbranch imagesbranch imagesbranch images