Skip to content

Commit 4bfb80a

Browse files
committed
ng20: adjustments to resource
@JohannesHoppe
1 parent 375e2c2 commit 4bfb80a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

blog/2025-05-angular20/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,55 @@ Please note that a resource is only meant for *retrieving* data from an API and
269269
Write operations such as create, update, or delete cannot be handled with a resource.
270270
You must continue to use `HttpClient` directly for those.
271271

272+
## API Adjustments to `resource` and `rxResource`
273+
274+
The Resource API remains *experimental* in Angular 20.
275+
This means the interface can still change without official prior notice.
276+
Recently, there have been two interesting adjustments.
277+
278+
We have updated our comprehensive [blog post on the Resource API](https://angular.schule/blog/2025-05-resource-api) accordingly, so you will always find up-to-date examples there.
279+
280+
### resource: `params` instead of `request`
281+
282+
Parameters for a resource are now passed via the `params` property, no longer via `request`.
283+
The property in the `ResourceLoaderParams` interface, from which we read the parameters, is now also called `params`.
284+
285+
```ts
286+
// ❌ BEFORE
287+
booksResource = resource({
288+
request: () => this.isbn(),
289+
loader: ({ request }) => this.#bs.getSingle(request)
290+
});
291+
292+
// ✅ AFTER
293+
booksResource = resource({
294+
params: () => this.isbn(),
295+
loader: ({ params }) => this.#bs.getSingle(params)
296+
});
297+
```
298+
299+
We welcome this change, as the terms "request" and "loader" could easily be confused before.
300+
With the term "params", it is now clearer that these are parameters that trigger the loader.
301+
302+
303+
### rxResource: `stream` instead of `loader`
304+
305+
The `rxResource` is a special variant of the Resource that uses an RxJS Observable as a loader (the simple Resource expects a Promise as a loader).
306+
An Observable can deliver any number of elements, so the term "loader" does not always fit.
307+
Therefore, the property has been renamed to `stream`.
308+
309+
```ts
310+
// ❌ VORHER
311+
booksResource = rxResource({
312+
loader: () => this.#bs.getAll()
313+
});
314+
315+
// ✅ NACHHER
316+
booksResource = rxResource({
317+
stream: () => this.#bs.getAll()
318+
});
319+
```
320+
272321

273322
## Miscellaneous
274323

0 commit comments

Comments
 (0)