Observable data lost on API call

Discussão em 'Angular' iniciado por Skafec, Outubro 18, 2024.

  1. Skafec

    Skafec Guest

    so I am using Spartacus as the base of the project. In spartacus the data for the product is caught with this search method:

    search(query: string | undefined, searchConfig?: SearchConfig): void {
    if (query) {
    this.store.dispatch(
    new ProductActions.SearchProducts({
    queryText: query,
    searchConfig: searchConfig,
    })
    );
    }
    }


    Now all of this is data is passed to the model$ Observable. In my project I have to implement show more which keeps the display of previous items and displays new items. When I call the function:

    getPageItems(pageNumber: number): void {
    this.routing
    .getRouterState()
    .subscribe((route) => {
    const routeCriteria = this.getCriteriaFromRoute(
    route.state.params,
    route.state.queryParams
    );
    const criteria = {
    ...routeCriteria,
    currentPage: pageNumber,
    };
    this.search(criteria);
    })
    .unsubscribe();
    }


    This updates the entire observable and I lose the previous product items. How can I keep track of the previous product items and push new product items?

    Continue reading...

Compartilhe esta Página