Problem Statement
How do you create a custom pipe and when should it be pure?
Explanation
Implement PipeTransform, decorate with @Pipe, and add a transform method. Default pipes are pure—Angular calls them only when input references change, which is fast. Mark a pipe impure (pure:false) only if it depends on mutable data that changes without new references; note it runs every change detection and can hurt performance.
Code Solution
SolutionRead Only
@Pipe({ name:'search' })
export class SearchPipe implements PipeTransform {
transform(list: any[], q: string){
if(!q) return list;
const s = q.toLowerCase();
return list.filter(x => x.name.toLowerCase().includes(s));
}
}