October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

Data Fetching with Resources in Angular: When to Use resource(), httpResource(), and rxResource()

Angular's resource APIs manage asynchronous reads as signals. Here is how to choose between resource(), httpResource(), rxResource(), and Router resources, and why writes stay on HttpClient.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Angular’s resource APIs bring asynchronous reads into signal-based code. You describe what the read depends on, supply a loader, and read the result as signals for value, status, and errors. Use resource() for a custom asynchronous loader, httpResource() when the read goes through Angular’s HttpClient stack, rxResource() when your source is already an RxJS Observable, and Router resources when the data belongs to a matched route. Mutations such as POST or PUT stay on direct HttpClient calls. Resources manage reads and request state; they do not replace writes.

Choosing the right API

The four APIs differ mainly in where the data comes from and where the loading state is surfaced. The table below lists the practical differences documented by Angular.

As an Amazon Associate I earn from qualifying purchases.

Need API What it gives you
General asynchronous read or custom loader resource() A loader that receives params, the previous status, and an AbortSignal. It can resolve once per request or emit repeatedly through stream. (Angular: Async reactivity with resources)
HTTP read through Angular’s configured HTTP stack httpResource() Requests go through HttpClient, so interceptors and HTTP testing apply. JSON is parsed by default, with text, Blob, and ArrayBuffer variants. (Angular: Reactive data fetching with httpResource)
Existing Observable-based source rxResource() Behaves like resource(), but the loader maps the request to an RxJS Observable. (Angular API: rxResource)
Data attached to matched routes Router resources configuration Routes load concurrently. Blocking is the default; nonBlocking() lets the component render its own loading and error states. (Angular: Data fetching with resources)
Create, update, or delete request Direct HttpClient calls Angular advises against httpResource() for mutations such as POST and PUT.

When you compare options for a specific screen, check four things: how the data source is represented (a Promise-returning loader, an Observable, an HTTP request, or route data); whether the operation is a read or a write; whether navigation should wait for the data or the component should render a loading state; and whether you need HttpClient interceptors or its testing utilities.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fetching data with resource()

A resource takes a reactive params function and a loader. Angular re-runs the loader when any signal read inside params changes. If a load is still in progress, it is aborted first. Pass the abortSignal to fetch or another cancellation-aware call so obsolete work actually stops.

import { resource, signal } from '@angular/core';

const userId = signal<number | undefined>(1);

const user = resource({
  params: () => (userId() === undefined ? undefined : { id: userId() }),
  loader: async ({ params, abortSignal }) => {
    const response = await fetch(`/api/users/${params.id}`, { signal: abortSignal });
    return response.json();
  },
});

In this sketch, setting userId to undefined makes params return undefined. Angular then skips the loader and the status becomes idle. This is the usual way to express “nothing to load yet” without a separate flag.

One result or a continuous stream

Use loader when each request produces one result. Use stream for sources that keep producing values, such as WebSockets, Server-Sent Events, or Firestore onSnapshot listeners. In that case the resource’s value can update more than once for the same set of params.

Reading state safely

A resource exposes status, value, error, isLoading, snapshot, and hasValue. Reading value while the resource is in an error state throws. Guard the read with hasValue() in templates and logic, and drive loading and error UI from the state signals. Skipping this check is the most common way a resource-based component breaks in production.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Using httpResource() instead of HttpClient

httpResource() is a reactive wrapper over Angular’s HttpClient. Interceptors, XSRF configuration, and HTTP testing all apply. Configure them with provideHttpClient(...) in the usual way. The main behavioral difference is timing: a resource starts eagerly as its request signals resolve, while a plain HttpClient Observable does nothing until something subscribes. When a reactive request value changes, the resource issues a new request and cancels the pending one.

Choose httpResource() over a bare HttpClient call when a template or signal-based computation needs the response as a reactive value and you want the loading and error state tracked for you. Keep a direct HttpClient call when you need explicit subscription control, when you are performing a write, or when the response is consumed in an imperative workflow rather than rendered.

Response types and parsing

JSON is the default response format. For other body types, use httpResource.text(), httpResource.blob(), or httpResource.arrayBuffer(). A parse option can validate or transform the response, and the return type of that function becomes the resource’s value type. Angular’s guide shows schema validation as an example, but it does not require any particular validation library.

Download progress

Set reportProgress: true to receive download progress; the latest figure is exposed through the resource’s progress signal. The Angular guide points out that this option covers downloads only. HttpClient’s newer options, which separate upload and download progress, are a different mechanism.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Observable sources with rxResource()

If your data layer already returns Observables, rxResource() keeps that code intact. Its loader maps the request to an RxJS Observable, and it otherwise behaves like resource(), with the same signal-based state. It is the natural choice when a service exposes streams and you want the result as a signal without converting every call to a Promise.

Router resources

Route resources bring data loading into the Router’s navigation cycle. Resources declared on matched routes load concurrently. By default they are blocking: the Router waits for them to complete, binds the resolved value to the component input, and cancels navigation if a load fails.

  • Blocking (default): the component activates only after the data arrives, so it never renders a loading state of its own.
  • Non-blocking: wrapping the resource with nonBlocking() activates the component immediately and exposes the full resource state, so the component can render loading and error UI.
  • Refreshing: calling reload(), or changing a tracked route parameter, refreshes the data without navigating again.

Track only the route fields the resource actually uses. If a resource reads the entire params object, it can refetch when an unrelated parameter changes, because the Router builds a new object on every navigation. Reading the specific key avoids that extra work. The Router guide’s timing comparison between sequential and parallel loading is a hypothetical illustration, not a measured benchmark.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Server rendering and hydration

During server-side rendering, a resource loader runs to produce the initial HTML. Unless its result is transferred, the browser runs the loader again during hydration. Giving the resource a unique id lets Angular place the resolved value in TransferState, so the client starts from the server’s result. The id must be unique within the application and identical on server and client.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not use this for user-specific data when the rendered HTML could be cached or shared. The cached value is serialized into the HTML, so anyone who receives that page can read it.

Keep mutations on HttpClient

Resources are designed for reads. Angular’s guidance is to use direct HttpClient APIs for mutations. The documentation also warns that cancelling a resource can prematurely abort a mutation, which is one more reason not to route writes through a reactive read. Angular’s exact guidance on httpResource reads: “Avoid using httpResource for mutations like POST or PUT.” (Angular, “Reactive data fetching with httpResource”)

A practical split looks like this: a resource loads the list or record a screen displays, and an event handler calls HttpClient to save a change. After a successful save, call reload() on the resource (or change the params signal) so the view reflects the new server state.

Version and availability

Angular’s API references list resource, httpResource, Resource, and rxResource as stable since Angular v22.0. Confirm the Angular version in your project (for example, with ng version) before adopting these APIs in an application on an earlier major version, and check the API reference for the version you run.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Angular’s signal documentation also states the underlying model: “A Resource gives you a way to incorporate async data into your application’s signal-based code and still allow you to access its data synchronously.” (Angular, “Async reactivity with resources”)

Common pitfalls

  • Reading value in an error state throws; check hasValue() or handle error() first.
  • Returning a request from params that is always defined means the loader always runs; return undefined when there is nothing to fetch.
  • Ignoring abortSignal lets stale requests finish and write old values, so pass it to every cancellation-aware call.
  • Using httpResource() for a POST or PUT moves a write into a read-oriented lifecycle.
  • Caching user-specific data through TransferState exposes it in server-rendered HTML.

For the full option list and current signatures, see the resource API reference, the httpResource API reference, the Resource type reference, and the rxResource API reference.

The Bottom Line

Use httpResource() when a signal-driven read goes through HttpClient and you want its loading and error state handled for you. Use resource() for custom asynchronous loaders, rxResource() for Observable sources, and Router resources for route-level data. Keep every create, update, and delete on direct HttpClient calls.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.