In the function below, I am trying to build the filteredProducts array by concatenating the value of the tmp array. The tmp array contains elements but after the concatenation, the filteredProducts array is empty.
Assume the boolean variable refineCriteria.bosch is true;
filterProducts(refineCriteria: Refine) {
this.filteredProducts = [];
let tmp = [];
let filtered = false;
if(refineCriteria.bosch) {
tmp = this.products.filter(product => product.brand == "Bosch");
this.filteredProducts.concat(tmp);
filtered = true;
console.log("tmp = " + tmp);
console.log("this.filteredProducts = " + this.filteredProducts);
}
if(!filtered) {
this.filteredProducts = this.products;
}
console.log("filteredProducts = " + this.filteredProducts);
this.filteredProductsEvent.emit(this.filteredProducts);
}