How can use signals as query parameters in Angular?

Discussão em 'Angular' iniciado por Ilya, Março 29, 2025.

  1. Ilya

    Ilya Guest

    I have pagination of a data table from which I get limit and offset and update requestParams$, wheт it updated - request being executed

    public requestParams$ = new BehaviorSubject<{
    limit: number;
    offset: number;
    }>({
    limit: 6,
    offset: 0,
    });

    handleOnPagination(currentPage: number) {
    const { limit } = this.requestParams$.getValue();

    const newOffset = (currentPage - 1) * limit;

    this.updateRequestParams({ offset: newOffset });
    }

    private updateRequestParams(
    params: Partial<{
    limit: number;
    offset: number;
    }>
    ) {
    const value = this.requestParams$.value;
    this.requestParams$.next({ ...value, ...params });
    }

    private loadData() {
    this.requestParams$
    .pipe(
    takeUntil(this.unsubscribe$),
    distinctUntilParamsChanged(['offset', 'limit']),
    tap(({ limit }) => {
    this.busy = true;
    this.paginationLimit = limit;
    }),
    switchMap(({ limit, offset }) =>
    this.service.getData({ limit, offset })
    )
    )
    .subscribe((wishesBooks)....


    How can this code be rewritten using signals? How can this code be rewritten using signals? Has anyone had experience using signals as query parameters?

    Continue reading...

Compartilhe esta Página