Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Modern Data Fetching Techniques in Angular

Modern Data Fetching Techniques in Angular

Modern Data Fetching Techniques in Angular

Avatar for Dhananjay Kumar

Dhananjay Kumar

May 07, 2026

More Decks by Dhananjay Kumar

Other Decks in Education

Transcript

  1. All signal APIs are synchronous signal computed input linkedSignal Async

    Data resource resource incorporates async data in signal-based code and reads that synchronously
  2. resource • Fetch data from the API • Update data

    locally • Asynchronously load local resource • It should not be used for mutation such as POST operations
  3. resource returns a WritableResource with read only signal- based properties:

    resource value status isLoading snapshot error hasValue()- boolean function
  4. resource status idle – The resource has no valid request

    and will not perform any loading. Here, value() is undefined. loading – The resource is currently loading a new value. Here, value() is undefined. reloading – The resource is currently reloading the new value. Here, value() is the previously fetched value. error – The resource failed to load the value. Here, value() is undefined. resolved – The resource has completed loading. Here, value() is returned from the loader. local – The resource value was set locally by set() or update().
  5. resource params it is tracked when signal used inside changes,

    angular executes the loader loader it is not tracked signal used inside change, angular does not execute the loader
  6. resource Angular does not track the signals used inside the

    loader. So, if a signal changed inside loader, Angular does not track this change and does not run the loader Angular tracks the signals used inside the params. So, if a signal changes in the params, Angular tracks this change and reruns the loader to fetch the updated data
  7. Multiple requests Whenever the productId changes, and if there is

    an overlap request, the resource API performs these tasks: • It reloads data by running the loader • It does not cancel the ongoing request but ignores its result • It only returns the result of the last request To cancel the previous, ongoing request when the productId changes, we have to use the abortSignal.
  8. httpResource • It is built on top of the resource

    primitive. • It uses HttpClient as its loader. • It serves as an abstraction for @angular/common/http. • It makes HTTP requests through Angular’s HTTP stack. • It works with interceptors.
  9. httpResource • httpResource creates a resource that loads data with

    an HTTP GET • The request updates when signal based url changes • It uses HttpClient, so you get interceptors, testing support, and the rest of the HttpClient stack • Responses are treated as JSON by default. But can be used with other parser such as httpResource.text()
  10. httpResource •It is eager • It triggers a request as

    soon as it is defined httpClient •It is lazy • It only triggers a request when the returned observable is subscribed to
  11. httpResource • Each new request made with the httpResource API

    automatically cancels the previous one. • Because of this behaviour, it is not suitable for mutations and should be used only for data fetching.
  12. Request parameters • url • method • body • params

    • headers • context • reportProgress • withCredentials • keepalive • cache • priority • referrer • timeout • transferCache
  13. Thank YOU • [email protected] • Training • Consulting • Speaking

    • MVP development • Product Development • API-AGENTS-AGNULAR