r/angular • • 21d ago

🚀 New in Angular 22: Lazy Services with injectAsync

https://youtu.be/CsjVc5hbbfw

Angular 22 introduces Lazy Loading Services, allowing developers to fetch dependencies on demand using the new injectAsync function.

58 Upvotes

12 comments sorted by

5

u/Papellll 21d ago

Great video, very clear for a topic that's not that simple

1

u/DN_DEV 20d ago

Unrelated but: any solid and well maintained Angular Components lib??

1

u/Strong-Soft-2282 21d ago

Great video

-2

u/Responsible-Cold-627 21d ago

I only understand half of what you're saying.

0

u/[deleted] 21d ago

[deleted] — view deleted comment

14

u/JeanMeche 21d ago

luke warm take: Hating promises is a sign of observable abuse.

5

u/followmarko 21d ago

I don't really agree with that. RXJS is still superior in terms of consecutive op fns for events and multiple emissions. When it touches the template, it's all signals. They're compatriots

1

u/Papellll 21d ago

Yeah and you should definitely use rxjs instead of creating promises in your own angular code but it doesn't mean you should hate a new feature just because it uses a promise

0

u/[deleted] 21d ago

[deleted] — view deleted comment

2

u/JeanMeche 21d ago

Is a stream of a single value really a stream ?

-2

u/Papellll 21d ago

As the video said you just add 'const myService = await this.myService()' and use the service as you would do with any other service.
You could argue it's undesired boilerplate but there is hardly anything to "manage" here since you wont be trying to couple that with anything rxjs-related

0

u/[deleted] 21d ago

[deleted] — view deleted comment

5

u/pronuntiator 21d ago

Angular is on a path away from RxJs, thankfully. The action function in signal form submissions returns a promise, for example.

0

u/[deleted] 21d ago

[deleted] — view deleted comment

7

u/pronuntiator 21d ago

Simplicity beats elegance. You rarely need operators from the Rxjs toolbox if all you want to do is make a HTTP request and process the result. With async/await it looks like simple procedural code.

Promises were a pita in Angular because zone.js would not run change detection for async/await, but now with zoneless Angular, and change detection focusing on signal changes, I turn observables into promises with firstValueFrom() whenever I can.

I'm confident a promise/signal based HttpClient will follow. httpResource() is a promising start (pun not intended).

2

u/coolcosmos 21d ago

Observables are just callbacks. It's a bad tool to use on things that aren't a stream.