<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/lazy-loading-services-in-angular-22-jyn2jy271" -->

---
title: Lazy Loading Services in Angular 22 | daily.dev
description: Angular 22 introduces injectAsync, a stable API for lazy-loading services on first use rather than bundling them upfront. Using a real offer-editor PDF export...
canonical: https://daily.dev/posts/lazy-loading-services-in-angular-22-jyn2jy271
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Lazy Loading Services in Angular 22 | daily.dev
og:description: Angular 22 introduces injectAsync, a stable API for lazy-loading services on first use rather than bundling them upfront. Using a real offer-editor PDF export...
og:url: https://daily.dev/posts/lazy-loading-services-in-angular-22-jyn2jy271
og:image: https://api.daily.dev/og/posts/jyn2jY271.png
og:image:alt: Lazy Loading Services in Angular 22
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Lazy Loading Services in Angular 22

**[Angular.love](https://daily.dev/sources/angularlove)** · 12 min read · 0 upvotes · 0 comments

## Summary

Angular 22 introduces injectAsync, a stable API for lazy-loading services on first use rather than bundling them upfront. Using a real offer-editor PDF export feature as an example, the piece explains how dynamic import() splits code into separate chunks, how services must be auto-provided (via @Injectable({providedIn:'root'}) or the new shorter @Service() decorator) to be resolvable once loaded, and how prefetch triggers like onIdle or a custom hover/focus-based trigger can start the download before the user clicks. It also covers default exports, chunk naming for debugging, the pitfall of stray ordinary imports defeating the split, and guidance on when the technique is worth the added async boundary.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://angular.love/lazy-loading-services-in-angular-22>

## Questions this post answers

### How do I lazy load a service in Angular 22 instead of bundling it in the main chunk?

Angular 22 introduces injectAsync, a stable function from @angular/core that loads a service the first time its instance is requested. You call it with a loader returning a dynamic import promise, for example injectAsync(() => import('@example/util-pdf-export').then(m => m.PdfExportService)), and use the resulting function inside an async method to await the instance. The service must still be auto-provided via @Injectable({providedIn:'root'}) or the new @Service() decorator, otherwise there's no provider to build once the chunk loads.

_daily.dev surfaces framework changes like this for teams trimming Angular bundle size._

### What does the new @Service() decorator do in Angular 22 compared to @Injectable({providedIn: 'root'})?

@Service() is a shorter decorator introduced in Angular 22 that registers a class in the root injector without arguments, covering the common auto-provided case, while @Injectable() remains necessary for services needing custom provider configuration. Passing @Service({autoProvided: false}) disables automatic registration, but a class configured that way cannot be used with injectAsync since no provider would be waiting when its chunk loads.

_developers migrating Angular DI patterns can track decorator changes like this via daily.dev._

### How can I prefetch a lazily loaded Angular service before the user clicks the button that needs it?

Pass a prefetch option to injectAsync whose value is a function returning a promise; Angular runs the loader once that promise resolves. The built-in onIdle trigger waits for a browser idle moment, optionally bounded with a timeout like onIdle({timeout: 1000}). A custom trigger can also fire on a hover or focus event using an effect that watches a viewChild signal for an element and resolves once a pointerenter or focusin event occurs, giving a sharper signal than idle time alone.

_daily.dev helps developers stay current on Angular performance techniques like prefetch triggers._

## Similar posts on daily.dev

- [Angular’s New injectAsync\(\) API Explained](https://daily.dev/posts/angular-s-new-injectasync-api-explained-aqo0mdr2h) · ITNEXT · 1 upvotes · 0 comments
- [Angular's new mantra](https://daily.dev/posts/angular-s-new-mantra-sqxe1yvmn) · Bytes by ui.dev · 67 upvotes · 3 comments
- [Angular 22: The Evolution of Modern Angular](https://daily.dev/posts/angular-22-the-evolution-of-modern-angular-tpdetu6wa) · Telerik · 0 upvotes · 0 comments

---

Tags: [#typescript](https://daily.dev/tags/typescript), [#angular](https://daily.dev/tags/angular), [#dependency-injection](https://daily.dev/tags/dependency-injection)

[View this post on daily.dev](https://daily.dev/posts/lazy-loading-services-in-angular-22-jyn2jy271)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Lazy Loading Services in Angular 22","url":"https://daily.dev/posts/lazy-loading-services-in-angular-22-jyn2jy271","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/lazy-loading-services-in-angular-22-jyn2jy271"},"datePublished":"2026-09-20T07:44:38.770Z","dateModified":"2026-09-20T07:50:41.243Z","description":"Angular 22 introduces injectAsync, a stable API for lazy-loading services on first use rather than bundling them upfront. Using a real offer-editor PDF export...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d87d6473e78751d63bb2441ece738f1b?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d87d6473e78751d63bb2441ece738f1b?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Angular.love","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Angular.love","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/b638946cd9c74bf6a260e4e6a40212d7","url":"https://daily.dev/sources/angularlove"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/lazy-loading-services-in-angular-22-jyn2jy271","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"typescript,angular,dependency-injection","timeRequired":"PT12M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Angular.love","item":"https://daily.dev/sources/angularlove"},{"@type":"ListItem","position":3,"name":"Lazy Loading Services in Angular 22"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/lazy-loading-services-in-angular-22-jyn2jy271#faq","mainEntity":[{"@type":"Question","name":"How do I lazy load a service in Angular 22 instead of bundling it in the main chunk?","acceptedAnswer":{"@type":"Answer","text":"Angular 22 introduces injectAsync, a stable function from @angular/core that loads a service the first time its instance is requested. You call it with a loader returning a dynamic import promise, for example injectAsync(() =\u003e import('@example/util-pdf-export').then(m =\u003e m.PdfExportService)), and use the resulting function inside an async method to await the instance. The service must still be auto-provided via @Injectable({providedIn:'root'}) or the new @Service() decorator, otherwise there's no provider to build once the chunk loads. daily.dev surfaces framework changes like this for teams trimming Angular bundle size."}},{"@type":"Question","name":"What does the new @Service() decorator do in Angular 22 compared to @Injectable({providedIn: 'root'})?","acceptedAnswer":{"@type":"Answer","text":"@Service() is a shorter decorator introduced in Angular 22 that registers a class in the root injector without arguments, covering the common auto-provided case, while @Injectable() remains necessary for services needing custom provider configuration. Passing @Service({autoProvided: false}) disables automatic registration, but a class configured that way cannot be used with injectAsync since no provider would be waiting when its chunk loads. developers migrating Angular DI patterns can track decorator changes like this via daily.dev."}},{"@type":"Question","name":"How can I prefetch a lazily loaded Angular service before the user clicks the button that needs it?","acceptedAnswer":{"@type":"Answer","text":"Pass a prefetch option to injectAsync whose value is a function returning a promise; Angular runs the loader once that promise resolves. The built-in onIdle trigger waits for a browser idle moment, optionally bounded with a timeout like onIdle({timeout: 1000}). A custom trigger can also fire on a hover or focus event using an effect that watches a viewChild signal for an element and resolves once a pointerenter or focusin event occurs, giving a sharper signal than idle time alone. daily.dev helps developers stay current on Angular performance techniques like prefetch triggers."}}]}
```

