Smart Code
Smart Code

Reputation: 15

Return filter search results is not working in angular

I have one search box in my angular application. Search result should be return two object values like product_name and product_content.But in my application it is taking only one object.But i want to apply search option for both like product_name and product_content.

filter.pipe.ts:

return products.filter((items) => {
  return (
    items.product_name.toLowerCase().includes(searchText), // Not working
    items.product_content.toLowerCase().includes(searchText) // working
  );
});

So, How to resolve this issue? If anyone knows help to find the solution.

Demo: https://stackblitz.com/edit/angular-selvam-ecommerce-task-mffqdn?file=src%2Fapp%2Fpipes%2Ffilter.pipe.ts

Upvotes: 0

Views: 414

Answers (1)

Abdelmlak Dhif
Abdelmlak Dhif

Reputation: 479

return products.filter((items) => {
  return (
    items.product_name.toLowerCase().includes(searchText.toLowerCase()) ||
    items.product_content.toLowerCase().includes(searchText.toLowerCase()) 
  );
});

Instead of , put an || to check both conditions.

Upvotes: 1

Related Questions