I have a list of strings that I want to iterate through, but I want to be able to filter them using a search term. Like this:
It's possible to leverage dependency injection into pipes. You could inject the component:
Then you can set a property on it to notify this:
@Pipe({
name: 'search'
})
export class SearchPipe {
constructor(@Inject(forwardRef(() => SomeComponent)) private comp:SomeComponent) {
}
transform(value) {
var filtered = value.map((v) => v-1);
this.comp.isEmpty = (filtered.length === 0);
return filtered;
}
}
The main drawback is that you link the pipe within the component. The advantage is that filtering is executed once.