Angular: From Zero to Expert

Angular: From Zero to Expert

injectAsync: Angular's Native Solution for Lazy-Loading Services

Angular 22 ships injectAsync — a first-party helper that lets you lazily load services through the DI system.

Amos Isaila's avatar
Amos Isaila
May 06, 2026
∙ Paid
Angular 22: injectAsync:  Lazy-Loading Services

If you’ve used ngxtension/inject-lazy, this will feel familiar. But the API is different, and the trade-offs matter.

Angular: From Zero to Expert is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.

The Problem

Bundle size. You have a ChartService that pulls in D3, a PdfService that imports pdfjs, or an AnalyticsService that loads a heavy SDK. These services aren’t needed on initial render — maybe they’re triggered by a button click, a route guard, or a conditional feature flag.

With providedIn: 'root', the service class and its dependencies end up in the main bundle regardless of whether the user ever triggers the code path that uses them.

Lazy routes solve this for route-level code splitting. But what about services used within a component that’s already loaded?

Before injectAsync: The Manual Approach

@Component({
  selector: 'app-report',
  template: `<button (click)="generate()">Generate PDF</button>`,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ReportComponent {
  private _injector = inject(EnvironmentInjector);

  async generate(): Promise<void> {
    const { PdfService } = await import('./pdf.service');
    const pdfService = this._injector.get(PdfService);
    pdfService.createReport();
  }
}
User's avatar

Continue reading this post for free, courtesy of Amos Isaila.

Or purchase a paid subscription.
© 2026 Amos Isaila · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture