Currently, I am creating a filtering system for a product list based on category IDs using the RXJS operator BehaviorSubject
.
However, I have encountered an issue with implementing infinite scrolling with Behavior Subject because I am unable to access the previous array of data (referred to as products) since it always reflects the latest updates.
Here is my Service setup:
private productsSource = new BehaviorSubject<Product[]>(null);
public products$: Observable<Product[]> = this.productsSource.asObservable();
async getProductsByCategory(category: string, page: string = '1'): Promise<void> {
const products = await this.http.get<Product[]>(`${environment.host + this.wooPath}products`, {
params: {
...environment.configtations,
category,
page,
lang: this.language,
per_page: '6',
not_tags: 'component'
}
})
.toPromise();
this.productsSource.next(products);
}
For handling pagination in loadMore function:
async loadData(event) {
// How should I proceed next?
}