resource
API:isLoading()
is the property through which we can understand if an asynchronous operation is still runninguserResource
using the new resource
API provided by Angular core.fetch
API to make the http request and cast the result to a Promise
of User
s.value
signal provided by resource and shown in the template.isLoading
property to know whether the operation is still running or not.object | json
is an angular pipe that is applied to an object. andjson
pipe is often used to convert objects (and array) into strings that would otherwise not be visible in the template.imports
property of the @Component
.resource
generics parameter instead:request
parameters (but we will use it in the next examples, so since there are no parameters we can just type it as void
)resource
API supports Promise
s we can also use async-await
:resource
API also offers a convenient reload
method to re-fetch:true
again when data are fetched, and returns false
value when the operation is completeduserId
.
When the signal is updated, data is automatically re-fetched.API/[user id]
), the endpoint will loads a different user at each API callrequest
parameter, that is userId
, using the second generic parameter:request
parameter is typed as number
:AbortSignal
.
When a new API call is started, the previous one, that is potentially still in progress, will be aborted: