- 204
- 744 863
Deborah Kurata
United States
เข้าร่วมเมื่อ 22 เม.ย. 2009
Tips and updates on Angular's newest features for anyone in the Angular community (or Angular-curious)
Signals in Action: Error Handling with rxResource
Issuing an HTTP request is fraught with peril!
In this video, we examine how to handle HTTP errors when using the rxResource API.
*Links*
Code: stackblitz.com/~/edit/sia-error-handling-deborahk
TH-cam video: "Signals in Action: Building an App": th-cam.com/video/LHgJP7MwTWY/w-d-xo.html
TH-cam video: "First Look at Angular's new resource() and rxResource()": th-cam.com/video/_KyCmpMlVTc/w-d-xo.html
HTTP response status codes: developer.mozilla.org/en-US/docs/Web/HTTP/Status
You can find the entire playlist for the: "Signals in Action" series here: th-cam.com/play/PLErOmyzRKOCobnHAC0RA5BwxGBageIhLv.html.
*Content*
00:00 HTTP requests and Errors
00:25 Sample Application
01:56 resourceRef error property
03:26 Formatting a user-friendly error message
04:46 Exposing a user-friendly error message
05:43 Displaying an error message
06:31 Exposing the error status
08:05 Reacting to HTTP errors
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
😊About Me
Hey! I'm Deborah Kurata
I'm a software developer and TH-cam content creator. I speak at conferences such as VSLive and ng-conf. I write articles for freeCodeCamp. And I'm a Pluralsight author with courses in the top 10 most popular (out of 7,000+) for over 5 years. For my work in support of software developers, I've been recognized with the Microsoft Most Valuable Professional (MVP) award, and I'm a Google Developer Expert (GDE).
View my TH-cam content: www.youtube.com/@deborah_kurata
Contact me on Twitter: @DeborahKurata
Or on Bluesky: @deborahkurata.bsky.social
Find my Pluralsight courses: www.pluralsight.com/profile/author/deborah-kurata
Access my freeCodeCamp articles: www.freecodecamp.org/news/author/deborah-kurata/
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
#angular
#angularsignals
#angularstatemanagementwithsignals
#angularstatemanagement
#angulartutorials
#angularforbeginners
#angularbestpractices
#angularerrorhandling
#errorhandling
#errorhandlinginangular
#handlinghttperrors
#angularv19
In this video, we examine how to handle HTTP errors when using the rxResource API.
*Links*
Code: stackblitz.com/~/edit/sia-error-handling-deborahk
TH-cam video: "Signals in Action: Building an App": th-cam.com/video/LHgJP7MwTWY/w-d-xo.html
TH-cam video: "First Look at Angular's new resource() and rxResource()": th-cam.com/video/_KyCmpMlVTc/w-d-xo.html
HTTP response status codes: developer.mozilla.org/en-US/docs/Web/HTTP/Status
You can find the entire playlist for the: "Signals in Action" series here: th-cam.com/play/PLErOmyzRKOCobnHAC0RA5BwxGBageIhLv.html.
*Content*
00:00 HTTP requests and Errors
00:25 Sample Application
01:56 resourceRef error property
03:26 Formatting a user-friendly error message
04:46 Exposing a user-friendly error message
05:43 Displaying an error message
06:31 Exposing the error status
08:05 Reacting to HTTP errors
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
😊About Me
Hey! I'm Deborah Kurata
I'm a software developer and TH-cam content creator. I speak at conferences such as VSLive and ng-conf. I write articles for freeCodeCamp. And I'm a Pluralsight author with courses in the top 10 most popular (out of 7,000+) for over 5 years. For my work in support of software developers, I've been recognized with the Microsoft Most Valuable Professional (MVP) award, and I'm a Google Developer Expert (GDE).
View my TH-cam content: www.youtube.com/@deborah_kurata
Contact me on Twitter: @DeborahKurata
Or on Bluesky: @deborahkurata.bsky.social
Find my Pluralsight courses: www.pluralsight.com/profile/author/deborah-kurata
Access my freeCodeCamp articles: www.freecodecamp.org/news/author/deborah-kurata/
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
#angular
#angularsignals
#angularstatemanagementwithsignals
#angularstatemanagement
#angulartutorials
#angularforbeginners
#angularbestpractices
#angularerrorhandling
#errorhandling
#errorhandlinginangular
#handlinghttperrors
#angularv19
มุมมอง: 374
วีดีโอ
Signals in Action: Providing a Service in root vs Component
มุมมอง 3.2K14 ชั่วโมงที่ผ่านมา
We often declare signals and retrieve data within a service. In this video, we examine how signals in a service are handled differently if the service is provided in "root" vs in a component. *Links* Code: stackblitz.com/~/edit/sia-providing-services-deborahk TH-cam video: "Signals in Action: Building an App": th-cam.com/video/LHgJP7MwTWY/w-d-xo.html TH-cam video: "First Look at Angular's new r...
Signals in Action: Loading Indicator
มุมมอง 3.4K21 วันที่ผ่านมา
We often display a loading indicator when retrieving data. This is especially useful if the user's connection is slow. This video demonstrates an easy way to display a loading indicator using signals. *Links* Code: stackblitz.com/~/edit/sia-loading-indicator-deborahk TH-cam video: "Signals in Action: Building an App": th-cam.com/video/LHgJP7MwTWY/w-d-xo.html TH-cam video: "First Look at Angular...
Signals in Action: Building an App
มุมมอง 4.7Kหลายเดือนก่อน
Learning signals is only the first step. Often, the more difficult next step is understanding when and how to apply signals in an application. In this video, we build a simple application using many of the new signal features. We start by creating a signal-based service. This service uses SWAPI (the public Star Wars API) to retrieve data and expose that data as signals. Then we build a simple c...
When Should We (NOT) Use a Signal effect()?
มุมมอง 4.5Kหลายเดือนก่อน
"An effect is an operation that runs whenever one or more signal values change." Does that mean we should use it anytime we want to react to changes in a signal? Angular v19 includes changes to effect, and introduces several additional signal features. Does that change the guidance? In this video, we walk through several scenarios, examining an effect() based approach and an alternate approach....
New Naming Conventions: Reviewing the new Angular Style Guide
มุมมอง 9K2 หลายเดือนก่อน
The Angular team is proposing some significant changes to how we name our Angular files and classes. Shortly after Angular 2 was released in 2016, the Angular team provided a detailed style guide. This style guide established a set of coding practices and promoted consistency. Now, 8 years later, the team is proposing a significant overhaul of that style guide. In this video, we walk through on...
First Look at Angular's new resource() and rxResource()
มุมมอง 9K2 หลายเดือนก่อน
Angular signals haven't had great support for asynchronous operations, until now! Angular v19, coming out next month, introduces a new experimental API called resource(). And an rxjs-interop API called rxResource(). These features revolutionize how we handle our HTTP requests! In this video, we take a first look at both resource() and rxResource() and how you can leverage them in your projects....
First Look at Angular's new linkedSignal()
มุมมอง 11K2 หลายเดือนก่อน
Angular version 19, coming out in November, will introduce a new experimental signal primitive: linkedSignal(). This video is a first look at linkedSignal() including its purpose and possible use cases. UPDATE: This feature is now in a prerelease of Angular v19: 19.0.0-next.11. I updated the code in the link below with the pre-release and added code to try out the new feature. *Links* Code: sta...
Angular Routing Explained
มุมมอง 4.4K2 หลายเดือนก่อน
Ever wonder how Angular routing works? The index.html file is the one true Web page of an Angular application. All of our views are displayed within this one page. Hence an Angular application is often called a "Single Page Application" or SPA. In most applications, we want five, ten, or hundreds of templates to take turns appearing on our Angular application's single page. How do we manage whi...
When to use take() vs takeUntilDestroyed()?
มุมมอง 3.7K4 หลายเดือนก่อน
I was recently asked if it would be better to use take(1) or takeUntilDestroyed() when issuing an HTTP request with HttpClient. In this video, we examine the take() operator, and evaluate its use with HTTP operations. We crack open the Angular and RxJS source code. Then we compare the take(1) and takeUntilDestroyed() operators for use in HTTP requests. *Links* Code: stackblitz.com/~/edit/take-v...
Don't use takeUntilDestroyed() with Angular's HTTP PUT, POST, or DELETE?
มุมมอง 5K4 หลายเดือนก่อน
Should you use takeUntilDestroyed() with an HTTP PUT, POST, or DELETE operation? The short answer is "Probably not!". In this video, we walk through a PUT operation and examine the reasons why you should not use takeUntilDestroyed() for mutation requests. *Links* Code: stackblitz.com/~/edit/put-takeuntildestroyed-deborahk TH-cam video: "Use takeUntilDestroyed to Unsubscribe from Angular's Obser...
Synchronizing Select Boxes with an Angular Signal Effect
มุมมอง 8K5 หลายเดือนก่อน
Syncing multiple select boxes isn't always easy, especially when they are populated from HTTP requests. In this video, we'll first take a procedural approach to synchronizing select boxes with signals. Then change to a reactive approach, using a signal effect. *Links* Sample code (procedural approach): stackblitz.com/~/edit/sync-select-procedural-deborahk Sample code (effect approach): stackbli...
Currying for More Generalized Angular Code
มุมมอง 6K5 หลายเดือนก่อน
Currying transforms a function with multiple parameters into a sequence of nested functions each with a subset of those parameters. This allows for the partial application of a function. How is that useful? Currying can aid in DRYing our code. With DRY, or "Don't Repeat Yourself" the goal is to reduce or eliminate duplicate code. In this video, we examine what currying is and use it to minimize...
Declare Variables in Templates: Angular's New @let Declaration (v18.1)
มุมมอง 7K6 หลายเดือนก่อน
With @let, new in Angular v18.1, we can declare and assign local variables in our template. That's right, I said template! In this video, we'll look at the @let declaration syntax, walk through some common scenarios, and evaluate some early best practices for using @let. *Links* Code: stackblitz.com/~/edit/let-declaration-deborahk TH-cam video: "Angular's New Template Syntax: Control Flow": th-...
Build Generalized DRY Angular Code with Generics
มุมมอง 13K6 หลายเดือนก่อน
Build Generalized DRY Angular Code with Generics
A Redux-like Pattern for Managing State with Angular signals
มุมมอง 15K6 หลายเดือนก่อน
A Redux-like Pattern for Managing State with Angular signals
Use takeUntilDestroyed to Unsubscribe from Angular's Observables
มุมมอง 6K7 หลายเดือนก่อน
Use takeUntilDestroyed to Unsubscribe from Angular's Observables
Access the Angular toSignal's read-only result as a writable signal!
มุมมอง 4.5K7 หลายเดือนก่อน
Access the Angular toSignal's read-only result as a writable signal!
Angular's New Output API: Emit notifications from your child components
มุมมอง 6K8 หลายเดือนก่อน
Angular's New Output API: Emit notifications from your child components
Angular's New Model Inputs: Two-way Communication with your Child Components
มุมมอง 12K8 หลายเดือนก่อน
Angular's New Model Inputs: Two-way Communication with your Child Components
New(ish) DateOnly Type in .NET 6 (C# 10)
มุมมอง 5438 หลายเดือนก่อน
New(ish) DateOnly Type in .NET 6 (C# 10)
Automatically Migrate to Angular's New Control Flow Template Syntax
มุมมอง 2.7K9 หลายเดือนก่อน
Automatically Migrate to Angular's New Control Flow Template Syntax
Angular's New Template Syntax: Control Flow
มุมมอง 4.4K9 หลายเดือนก่อน
Angular's New Template Syntax: Control Flow
JavaScript Array with() Method (new in ES 2023)
มุมมอง 3.2K11 หลายเดือนก่อน
JavaScript Array with() Method (new in ES 2023)
JavaScript Array sort() vs toSorted() (new in ES 2023)
มุมมอง 2.4K11 หลายเดือนก่อน
JavaScript Array sort() vs toSorted() (new in ES 2023)
There is a lot of boilerplate code. Isn't it too complex for an advanced form?
So I am clear on your question, which part of this code are you referring to? The error handling is in a generalized function that can be reused in any application. On my Angular projects, one goal is to keep the component code as simple as possible. Hence the reason that the service provides the specific signals that the component needs. But if you are comfortable with working with the resourceRef object in the template, you could make that public (instead of private as I have) and access all of those properties (isLoaded, error) directly in the component.
Is there a reason to make a reference in the component and set the reference in the HTML? Why not directly set the property from the service in the HTML? Readability?
Separation of concerns I would say
Yes, separation of concerns. I like to think of the component as the mediator between the service and the view. Plus it makes it easier to make additional modifications to the data or react to changes in that data in the component, as needed. It's difficult to see that benefit in my very simple sample application, because all I'm doing with that data is display it. But in more *real* applications, there is often data interaction. Some of that interaction may require additional computations or other logic.
#FIRST :D
You are the best, Deborah!
Thank you so much!
spec files ? you don't use Cypress ?
Are you asking about .spec file naming conventions? Or looking for them in my sample application? No, I don't use Cypress.
@@deborah_kurata Cypress is so useful and much better than Angular test...
@@deborah_kurata it works with Google Chrome video recorder
@@deborah_kurata th-cam.com/video/-RJuZrq-wOk/w-d-xo.html
Que elegancia! ❤
Gracias! 😊
The resource api looks great, but is there something we can do about caching? Is angular going to develop some feature about optimizing it?
Yep! I'm enjoying using the resource api. Could you elaborate on caching? Are you referring to caching data? Signals in a service provided in "root" are "cached" and stored in the signal for the lifetime of the application. Regarding optimization, I'm not clear on your question. Are you referring to optimizing data retrieval? Or component loading?
@@deborah_kurata thanks for the reply. I meant caching using the resourceapi :) if there was something to leverage caching of requests
So something like this: developer.mozilla.org/en-US/docs/Web/HTTP/Caching As I mentioned, signals in a service provided in "root" handles the "private" caching.
@@deborah_kurata thanks! :)
Would be interesting to see an example with 3 nested components
Gold for beginners
Thank you! And since these are new features, the videos should be useful for experienced Angular developers as well. 😊
Great Video Deborah, I was going to ask some questions till you mentioned that it will be covered in the next videos 😅
Thanks! Glad you're liking the series. 😊 Hope I'm able to answer all of your questions over the next several videos!
I am subscribing to ur courses in pluralsight u never update your courses there and don't release any course like angular to azure deployment
I kept the "Getting Started" carefully updated through every release and change for over 5 years. Pluralsight no longer allows me to update the "Getting Started". They said that they already have a "Fundamentals" course and that the "Getting Started" was unnecessary. They have then retired almost all of my courses. (I think there may be one remaining.) At this point in time, I don't expect to do any future courses on Pluralsight. My new content will be done here on TH-cam.
Do you plan on reworking "Getting started" on YT (or somewhere else) as a series of videos? Previously, your Pluralsight course was my first pick when I needed to recommend something to our interns when starting with Angular. It would be nice to have a go-to place again that could lead them into Angular world from scratch to advanced topics in a structured way.
@@mnemanja Thank you so very much for the kind words about my Pluralsight course. 😊 I originally thought I'd do a "getting started" on YT, but then found that there is no way to edit any published content. (You can cut out content, but not add/edit or replace any content.) So I would spend months to create a new "Getting Started" course and a few months later it would be out of date. I've heard that YT may be adding features to better support "courses", but I don't know what that would look like or how soon it would be available. I've looked for other places to potentially publish a course, but haven't found anything that meets my requirements: Easy for developers to find, easily update content, does not impose extra restrictions/requirements on the author (course length, face vs demos/illustrations, etc.) I have been trying to put my content here into playlists to have a basic order for watching all the content. But that doesn't really replace a well thought out course.
Very good change.
Yep! I really like the new control flow syntax!
Thanks for explanation!
Thank you for watching! 😊
Happy new year Deb!
Thank you! All the best in 2025! 😊
Great! Thanks 🌞
Thank you! 😊
Thanks for the lesson, really helped me😊
Thank you! Glad it was helpful! 😊
I've learned so much from your videos and want to say thank you for all the content you have created and continue to create. Your teaching techniques are unique, and your examples are easy to follow, making it easy to fully understand the topics you cover. You're Awesome Deborah!
That is very kind of you to say. Thanks so much! 😊
You legend!
Thank you! 😊
This was serendipitous for me! I was struggling with this issue as the documentation is not clear. I just realized if you declare the service as 'root' but then use the providers attribute in your component, angular doesn't regard the service as a singleton and overrides the 'root' declaration. Thanks!
Glad it was helpful. And yes, you want to clearly decide whether to provide a service in root or component. You rarely ever would want both. 😊
Hello, good day. I have a question: I have an RxResource that handles an HTTP request, and I want it to trigger another RxResource to make another request as a secondary action when it finishes. How would I do that?
Hi! I'm planning on several other videos on rxResource to cover more scenarios. 😊 To answer your question, you could do something like this: // Get the posts postsResource = rxResource({ loader: () => this.http.get<Post[]>(this.postUrl).pipe( tap(() => console.log("Post Data Retrieved")) ) }) // Only after the posts, get the user for the first post userForPostResource = rxResource({ request: this.postsResource.value, loader: (posts) => this.http.get<User[]>(`${this.userUrl}/${posts.request?.[0].userId}`).pipe( tap(() => console.log("User Data Retrieved", posts.request?.[0].userId)) ) }) See the sample project here: stackblitz.com/~/edit/secondary-request-rxresource-deborahk
@ Hi Deborah! Thanks for the great explanation and code example. I have a follow-up question: Is there a way to trigger the request without relying on any signal? For example, let’s say the first request is fine and updates a field, but then I want to fetch the updated list again. What would be the best approach to achieve this? Thanks in advance for your insights! 😊
@@cristophersaraosverdugo5934 The resourceRef has a reload() method that re-executes the loader function if you want to re-fetch the current data. That's also on my list for a YT video. 😊
@ ❤️❤️❤️❤️❤️ Thank you very much!!!!
Beautifully explained ❤
Thank you! 😊
If I keep providedIn: "root" and leave it as a singlet and add the service to the component's provider, is there a problem?
I have not experimented with this, but my guess is: The shared instance would be created. But any component that provides the service would get its own instance of the service, not the shared instance. Any component (or other service) that injects the service and does not provide it would get the shared instance.
But let's clarify one thing for those who might be pondering about the word "Signals" in the title: this is just how Angular works and it is not specific to signals. The same principle of instantiation and lifespan applies also to a service with a subject, as well as plain regular fields.
Yes, you are correct. I should have made a point to say that. Where this is important to signals is when using resource and rxResource. When using RxJS, the data is retrieved when something subscribes, so you can control better when the retrieval works. With resource and rxResource, if you don't have a request parameter, the loader function will execute when the service is initialized.
Thank u very much for ur efforts i hope to meet you one day ❤️
Thank you for watching! I'm often at Angular (like ngConf) and .NET conferences (such as VSLive).
Thank you Deborah! It is worth to mention that the instance of the service provided at component level it is shared by all sub-components. Sub-components should not include the service in its providers array to access the parent component instance. So it is a singleton in the scope of its hierarchy. Am I correct?
Yes! That's correct. A service provided in a component is shared with its subcomponents. (But I think it would be confusing to call it a "singleton" in that case.)
Great / clear examples and video once again!! - Do you have plans to use Async / Await with sequential http calls?
Thank you! I normally use RxJS operators for sequential HTTP calls. I haven't gotten into the async / await patterns. Maybe that's something I should look into?
@@deborah_kurata its something I have been trying to experiment with because I want to try and remove RxJS as much as possible for making HTTP Requests so that new devs can jump in and use Fetch with Async / Await - or something like that that they might be more used to. I have hear rumblings about RxJS becoming optional in future release so my assumption is Angular will use Fetch but who knows lol. Once again thanks for your videos and replies.
👏👏
🙏🏼😊
Hello Deborah, thank you for the tutorial. I noticed that you are using 2 effects. Since everyone keeps demoing effects inside a constructor, I got the wrong impression that we can have only one effect. I'm so glad that we're allowed to have more than one.
You're welcome! It's great to clear up misconceptions! 😊 Yes, you can have as many effects as you need. In my example, I could have made that one effect. But then it would log whenever either of the signals changed and it wouldn't be clear exactly when one changed vs the other.
@@deborah_kurata that's exactly the issues I was facing, but didn't know the solution until now. Ironically, I learned something on effect from a video on service scopes 😇
Informative as usual😉
Thanks! 😃
It continues to be the best channel about Angular. Congratulations! 🎉🎉
Thanks so much! 😊
Do you have a video on developing a library of standalone components?
Hashed properties are completely private and cannot be accessed from outside the class. As a result, decorators that attempt to access these properties will fail. So from my perspective, we should carefully consider whether we really want to use "#" in Angular.
Yep. Do you use a lot of decorators?
@@deborah_kurata Yes. I use typestack/class-transformer a lot, which adds useful decorators to DTO files. It's useful for communicating with backend APIs, e.g. for String → Date conversion or even grouping fields depending on the CRUD operation being performed. A bit inspired by NestJS.
I do not have a app.config.ts file. Running v16 and I read that app.config.ts is deprecated. Also I am using standalone components. How can I set/configure WithComponentInputBinding. Must I do this in my routes file or the component itself?
I'm not sure where you heard app.config.ts was deprecated. I just created a new Angular CLI project (v19) and it creates an app.config.ts file. 🤷🏼♀️ If you don't want to use an app.config.ts file, you just add your providers array directly into the bootstrapApplication() code. So instead of something like this in your app.config.ts file: export const appConfig: ApplicationConfig = { providers: [ provideZoneChangeDetection({ eventCoalescing: true }), provideHttpClient(), provideRouter(routes, withComponentInputBinding())] }; You'd have something like this (in main.ts): bootstrapApplication(AppComponent, { providers: [ provideZoneChangeDetection({ eventCoalescing: true }), provideHttpClient(), provideRouter(routes, withComponentInputBinding())] }).catch((err) => console.error(err)); Does that answer your question?
@@deborah_kurata Thank you for your reply. Probably it's removed from the project in the past by another member. I never noticed before. I will try your approuch. again thank you for your fast reply
Crisp and awesome concept explanation, thanks again 👍
Glad you found it helpful! 🎉 Thank you!
Thanks for sharing Deborah!
Thank you for watching! 😀
Explained very well, keep it up. :)
Thanks for watching! 😊
Hi Deborah, in the video you give an example of primitives being immutable. So the code total = 42; // (1) total += 10; // (2) means that in (1), total is pointing at a memory with value 42. Then, in (2), total is pointing at a different memory address with value 52. But how can we re-access the value 42 ?? (We don't know the memory address for this anymore ?)
Thanks for your help, there's is a same concept of mutability and immutability in python also
Yep! Immutability is a powerful concept across many languages! 😊
So except for http calls which is unavoidable observable , we can replace all the other observable like subjects with signals , is it ? 🤔. And is that th new norm going to be ?
Thank you for watching the video! Http calls are not necessarily unavoidable. You can use fetch instead of HTTP Client to retrieve data using promises. Personally, I prefer HTTP Client (which as you said returns an observable). Using signals won't necessarily replace all Observables, especially when dealing with event-based actions. Things like tracking/reacting to keypresses, when you want every emitted value, you'll still want Observables. So yes, signals will replace many observables, especially those used to manage state. But we'll still want observables for event-based actions.
Could this completely replaxe ngrx in your opinion?
For simple applications, yes. For more complex applications and for large teams, probably no. And ngRx, and of course signalStore, are becoming more signal based.
7:24 this sounds like combineLatest. So would this be the best practice to replace combineLatest with this approach?
In some cases, yes. Especially those cases where combineLatest was used to handle multiple query parameters. In other cases, there may still be use for combineLatest, such as when handling events from multiple sources (keypress and mouse move for example).
The gold standard of teaching, not simply for Angular. We are blessed to have you.
That is so very kind of you to say! I appreciate that! 😊
I've seen some great Angular and rxjs teachers, but I think you are the best among them. Love your content
Thank you so very much! 😊 Thanks for watching!
Awesome
Thanks!
Happy new year. I went through your courses and all are so nicely explained ❤.Thanks
Thank you so much! All the best in 2025! 😊
CTRL + SHIFT + L made my day!
Great tooling for the win! LOL. Glad it was useful. 😊
Thank you very much!
I'm glad you found it helpful! 😊
This is by far the best video on angular signals that I have come across...thank you so much for the content....
Thank you! I'm really glad you enjoyed it! 😊
Another great video again. Would you please advise me can I use resource() or rxResource() to replace combineLatest in rxjs?
Thanks! Do you have a code snippet of your combineLatest so I have a clear idea of your objective? I used to use combineLatest to do something with a retained observable when another observable changes. If these are all signals instead, the linkedSignal() can often do the same job. It depends on your specific scenario.
@@deborah_kurata I meant that if I can use Resource or RxResource to handle multiple http request. It seems that it can only handle one request with loader function in Resource or RxResource. To handle multiple request, it seems that we still can not avoid to use combineLatest. I asked Grok AI. It gave me the answer. `import { inject, Injectable } from '@angular/core'; import { resource } from '@angular/core'; import { HttpClient } from '@angular/common/http'; @Injectable({ providedIn: 'root' }) export class MultiResourceService { private http = inject(HttpClient); combinedResource = resource({ loader: async () => { const [users, products] = await Promise.all([ this.http.get<User[]>('url1').toPromise(), this.http.get<Product[]>('url2').toPromise() ]); return { users, products }; } }); }` or another way `private http = inject(HttpClient); usersResource = rxResource({ loader: () => this.http.get<User[]>('url1') }); productsResource = rxResource({ loader: () => this.http.get<Product[]>('url2') }); combinedResource = combineLatest([this.usersResource.result$, this.productsResource.result$]).pipe( map(([users, products]) => ({ users, products })) ); combinedResource.subscribe(result => { console.log(result.users, result.products); });`
Or you could do something like this, which prevents the need for any subscriptions or async/await: combinedResource = rxResource({ loader: () => combineLatest([ this.http.get<Post[]>(this.postUrl), this.http.get<User[]>(this.userUrl) ]) }); posts = computed(() => this.combinedResource.value()?.[0] ?? [] as Post[]); users = computed(() => this.combinedResource.value()?.[1] ?? [] as User[]); To make it easier to work with the returned array of arrays, you could add array destructuring like this: combinedResource = rxResource({ loader: () => combineLatest([ this.http.get<Post[]>(this.postUrl), this.http.get<User[]>(this.userUrl) ]).pipe( map(([posts, users]) => ({ posts, users})) ) }); posts = computed(() => this.combinedResource.value()?.posts ?? []); users = computed(() => this.combinedResource.value()?.users ?? []); See the stackblitz here: stackblitz.com/~/edit/combinelatest-rxresource-deborahk
simple clear and even fun
Yep! Signals are fun! Thanks