I have a function that returns all the products, if and only if a specific category is defined inside the object.
What I am trying to do is to pass an array parameter on the function with an array of categories names like [banana, apple, orange]
and I want to get all the products that have these fruits as categories.
the problem is, I need to pass an array in that function.
const categories: string[] = ['apple', 'banana', 'orange'];
get_sugested_products_by_category(categories) {
this.products_collection = this.afs.collection('products', ref =>
ref.where(`category.${category}`, '==', true)
);
return this.products = this.products_collection.valueChanges();
}
And I was thinking if is possible to make a query like this bellow:
categories.forEach(category => {
this.products_collection = this.afs.collection('products', ref =>
ref.where(`category.${category}`, '==', true)
);