Skip to content

Commit df8a959

Browse files
committed
resource: ResourceStatus type
1 parent ed996cc commit df8a959

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

blog/2025-05-resource-api/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ booksResource = resource({
142142
The loader is executed immediately when the Resource object is initialized. The Resource processes the response and offers the following signals to work with the data:
143143

144144
- `value`: loaded data, here `Book[]`
145-
- `status`: state of the Resource, type `ResourceStatus`, e.g., *Resolved* or *Loading*, see next section
145+
- `status`: state of the Resource, type `ResourceStatus`, e.g., `resolved` or `loading`, see next section
146146
- `error`: error
147147

148148
We can display the loaded books in the template like this:
@@ -157,16 +157,16 @@ We can display the loaded books in the template like this:
157157

158158
## Status of the Resource
159159

160-
Using the `status` signal, we can evaluate the state of the Resource, e.g., to show a loading indicator. All `status` values are fields from the [`ResourceStatus` enum](https://angular.dev/api/core/ResourceStatus):
160+
Using the `status` signal, we can evaluate the state of the Resource, e.g., to show a loading indicator. All `status` values are defined by the [`ResourceStatus` union type](https://angular.dev/api/core/ResourceStatus):
161161

162162
| Status from `ResourceStatus` | Description |
163163
| ---------------------------- | ----------------------------------------------------------------------- |
164-
| `Idle` | No request is defined and nothing is loading. `value()` is `undefined`. |
165-
| `Error` | Loading failed. `value()` is `undefined`. |
166-
| `Loading` | The Resource is currently loading. |
167-
| `Reloading` | The Resource is reloading after `reload()` was called. |
168-
| `Resolved` | Loading is complete. |
169-
| `Local` | The value was overwritten locally. |
164+
| `idle` | No request is defined and nothing is loading. `value()` is `undefined`. |
165+
| `error` | Loading failed. `value()` is `undefined`. |
166+
| `loading` | The Resource is currently loading. |
167+
| `reloading` | The Resource is reloading after `reload()` was called. |
168+
| `resolved` | Loading is complete. |
169+
| `local` | The value was overwritten locally. |
170170

171171

172172
For a loading indicator, we could process the state in a computed signal and return a boolean if the Resource is currently loading:
@@ -175,7 +175,7 @@ For a loading indicator, we could process the state in a computed signal and ret
175175
import { resource, computed, ResourceStatus } from '@angular/core';
176176
// ...
177177

178-
isLoading = computed(() => this.booksResource.status() === ResourceStatus.Loading);
178+
isLoading = computed(() => this.booksResource.status() === 'loading');
179179
```
180180

181181
```html
@@ -185,7 +185,7 @@ isLoading = computed(() => this.booksResource.status() === ResourceStatus.Loadin
185185
```
186186

187187
To cover all cases, we also need to account for the `Reloading` state.
188-
Using the built-in `isLoading` property solves this quickly: this signal returns `true` if the Resource is in the `Loading` or `Reloading` state:
188+
Using the built-in `isLoading` property solves this quickly: this signal returns `true` if the Resource is in the `loading` or `reloading` state:
189189

190190
```html
191191
@if (booksResource.isLoading()) {

0 commit comments

Comments
 (0)