Disclaimer: I am a consultant at Amazon Web Services, and this is my personal blog. The opinions expressed here are solely mine and do not reflect the views of Amazon Web Services (AWS). Any statements made should not be considered official endorsements or statements by AWS.
Having a search box & filtering out the list based on the text of that search box is a common development task in almost every software application.
In this post, we will understand how can we achieve the same functionality in Angular 7 using Pipe.
Pipes are a useful feature in Angular. They are a way to transform one value into another inside an Angular template. There are some built-in pipes, but we can also create our own custom pipes. You can more read about pipes on Angular's website - https://angular.io/guide/pipes.
In this post, I am using a list of complex objects for filtering purposes, instead of having a simple list of strings. In our case, the component will somehow look like the below.
Now we want to filter this list based on the category name. To do this, we did two things.
searchText
which is a string property of the component.categories
. Now, our template markup will look like this.Also, don't forget to register this filter pipe in app.module.ts
file inside declarations
array.