Angular’s new injectAsync() API explained

Опубликовано: 17 June 2026
на канале: Brian Treese
3,579
237

Lazy-loading Angular services used to be awkward, injectAsync() changes that.

🚀 Want to master Angular Signal Forms?
I just released a full course where we build a real Signal Form step-by-step covering validation, async validation, dynamic fields, custom controls, and submission patterns.

👉 Enroll here:
https://www.udemy.com/course/angular-...

In this video, we take a real Angular markdown preview feature and refactor it using Angular v22’s new injectAsync() API. Along the way, we’ll lazy load a service, reduce the initial bundle size, remove a bunch of awkward injector boilerplate, and explore how prefetching with onIdle() works behind the scenes. You’ll also see how dynamic imports, dependency injection, and lazy-loaded chunks work together in modern Angular applications.

If you’ve ever wondered how to keep heavy libraries out of your initial bundle while still using Angular DI correctly, this video walks through the entire process step-by-step with a practical real-world example.

------------------------------------------------------------------------------

🔔 Subscribe for more Angular tutorials & tips → [🔗 https://www.youtube.com/c/briantreese...]
👍 Like this video if you found it helpful, it really helps support the channel!

------------------------------------------------------------------------------

🔗 Demo Links:
https://github.com/brianmtreese/angul...

------------------------------------------------------------------------------

📚 Additional Resources:
The commit that made this possible: https://github.com/angular/angular/co...
Angular Dependency Injection Guide: https://angular.dev/guide/di
Dynamic Imports (MDN): https://developer.mozilla.org/en-US/d...
My course "Angular: Styling Applications": https://www.pluralsight.com/courses/a...
My course "Angular in Practice: Zoneless Change Detection": https://app.pluralsight.com/library/c...

------------------------------------------------------------------------------

📖 Chapters:
0:00 – Introduction
0:20 – Why These Libraries Load Too Early
1:39 – Why the Markdown Libraries End Up in the Bundle
3:44 – Manually Lazy Loading an Angular Service
5:14 – Testing the Manual Lazy Loading Version
5:56 – Replacing Boilerplate with injectAsync()
7:31 – Testing Angular’s New injectAsync() API
8:08 – Prefetch Lazy Dependencies with onIdle
9:24 – When injectAsync() Actually Makes Sense

------------------------------------------------------------------------------

🧰 About the Tools Used
This video covers Angular v22’s new injectAsync() API for lazy-loading services with Angular Dependency Injection. We also explore dynamic imports, signals, onIdle() prefetching, bundle optimization, and modern Angular performance using a real markdown preview example powered by marked and highlight.js.

------------------------------------------------------------------------------

🎓 Angular Certification (New)
If you’re looking to validate your Angular skills, there’s now an official certification built and reviewed by Google Developer Experts.

It covers modern Angular concepts and is one of the first structured ways to demonstrate real-world Angular knowledge.

👉 https://certificates.dev/angular?frie...

(They’re currently offering up to 50% off)

------------------------------------------------------------------------------

#angular #angular22 #injectasync #javascript #webdevelopment #frontenddevelopment #angularsignals #typescript #programming #softwareengineering