Creating a reusable loader for angular v19 resource API with 2 request parameters of different...

Discussão em 'Angular' iniciado por st_clair_clarke, Janeiro 3, 2025.

  1. Below is the code that creates an angular19 reusable resource loader and its usage with a single request parameter:

    import { ResourceLoaderParams } from "@angular/core";

    function todoLoader({ request: todoId, abortSignal }: ResourceLoaderParams<number>): Promise<Todo> {
    return fetch(
    `https://jsonplaceholder.typicode.com/todos/${todoId}`,
    { signal: abortSignal }
    ).then((res) => res.json() as Promise<Todo>);
    }

    todoResource = resource({ request: this.todoId, loader: todoLoader });


    My difficulty is that I cannot find a way to have two (2) request parameters. I would like to add a second parameter 'appName' of type 'string' to the request parameter.

    Appreciate your help

    Continue reading...

Compartilhe esta Página