I want to retrieve data based on the IDs in an array. If the array is empty, I want all the data to be fetched. How can I achieve this?
selectedProductGroups: number[] = [];
products: Product[];
getProducts() {
this.generic?.Get_All("Products/Generic_Method").pipe(map(items => items.filter(items => (this.selectedProductGroups.includes(items.productGroupID) && this.selectedProductGroups.length>0)))).subscribe({
next: (data) => { this.products = data; console.log(this.products) },
error: (err) => { console.log(err) },
complete: () => {
}
});
}
this.products = [id=1] [id=2] [id=3] [id=4];
if(selectedProductGroups == [1,2])
{
this.products = [id=1] [id=2]
}
if(selectedProductGroups == empty)
{
this.products = [id=1] [id=2] [id=3] [id=4]
}