Using Angular v18 resource with HttpClient

Discussão em 'Angular' iniciado por MageWind, Dezembro 6, 2024.

  1. MageWind

    MageWind Guest

    I'm trying to update my code to use the new Resource type. The Angular documentation for Resource has this example:

    const userId: Signal<string> = getUserId();
    const userResource = resource({
    request: () => ({id: userId()}),
    loader: ({request, abortSignal}): Promise<User> => {
    // fetch cancels any outstanding HTTP requests when the given `AbortSignal`
    // indicates that the request has been aborted.
    return fetch(`users/${request.id}`, {signal: abortSignal});
    },
    });


    My question is what's the proper way to use the abortSignal when making requests using HttpClient (i.e. instead of fetch from the snippet)?

    Continue reading...

Compartilhe esta Página