httpResource and resource: Signal-Based Data Loading
The Problem They Solve
In the last lessons you wrote loading, error and data signals by hand. A resource bundles these three together and reloads automatically when its input signals change.
Version note:
resource, rxResource and httpResource arrived as experimental in Angular 19 and 20 and are stable in recent versions such as Angular 22 (June 2026). Check angular.dev for details of your version, because some option names changed while they were in preview.
httpResource
typescript
import { httpResource } from '@angular/common/http';
@Component({
selector: 'app-user-detail',
templateUrl: './user-detail.html',
})
export class UserDetail {
id = input.required<number>();
// runs again whenever id() changes
user = httpResource<User>(() => `/api/users/${this.id()}`);
}
html
@if (user.isLoading()) {
<p>Loading...</p>
} @else if (user.error()) {
<p>Could not load user.</p>
<button (click)="user.reload()">Retry</button>
} @else if (user.hasValue()) {
<h2>{{ user.value().name }}</h2>
<p>{{ user.value().email }}</p>
}
| Property | Meaning |
|---|---|
value() | Latest data (or undefined) |
hasValue() | True when a value exists |
isLoading() | Request in progress |
error() | Error if it failed |
status() | idle, loading, reloading, resolved, error, local |
reload() | Run the request again |
Search with Reactive Parameters
typescript
export class UserSearch {
term = signal('');
page = signal(1);
results = httpResource<User[]>(() => {
const q = this.term();
if (!q) return undefined; // undefined = do not request
return {
url: '/api/users',
params: { q, page: this.page() },
headers: { 'X-App': 'demo' },
};
});
}
html
<input #box (input)="term.set(box.value); page.set(1)" placeholder="Search users">
<button (click)="page.update(p => p + 1)">Next page</button>
@for (u of results.value() ?? []; track u.id) { <p>{{ u.name }}</p> }
Debounce: Every change of
term() starts a new request and cancels the previous one. For typing, debounce the signal first (for example with toObservable(...).pipe(debounceTime(300)) and back to a signal) to avoid too many calls.
resource: Any Async Source
typescript
export class Weather {
city = signal('London');
weather = resource({
params: () => ({ city: this.city() }), // option name may be `request` in older versions
loader: async ({ params, abortSignal }) => {
const res = await fetch(`/api/weather?city=${params.city}`, { signal: abortSignal });
if (!res.ok) throw new Error('Failed');
return (await res.json()) as WeatherData;
},
});
}
rxResource: Observable Loader
typescript
products = rxResource({
params: () => ({ category: this.category() }),
stream: ({ params }) => this.http.get<Product[]>('/api/products', { params }),
});
Resource or HttpClient?
| Use | When |
|---|---|
httpResource | Simple reads that depend on signals, such as detail pages and searches |
HttpClient + RxJS | Writes (POST, PUT, DELETE), complex pipelines, retry, caching, combining requests |
| Both | Typical apps read with resources and write with HttpClient, then call reload() |
typescript
save(user: User) {
this.http.put(`/api/users/${user.id}`, user).subscribe(() => this.userResource.reload());
}
Parse responses: Use the
parse option of httpResource to validate or convert the JSON, for example with a schema library, so wrong data is caught early.
Conclusion
A resource turns async loading into signals: value, isLoading, error and reload. It re-runs when its source signals change. Use it for reads and HttpClient for writes.
Quick Summary: httpResource(() => url) gives value/isLoading/error/reload.

