Reputation: 13
In my application I am using pipe a couple of times. my html code
And this is how my pipe looks like
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'highlightSearch',
pure: false
})
export class HighlightSearchPipe implements PipeTransform {
transform(value: any, args: any): any {
// console.log('args', args);
if (value && args && args.trim()) {
console.log('args', args);
return value.replace(new RegExp( '(' + args + ')', 'gi'), '<b>$1</b>');
}
return value;
}
}
And when I run my application, I could see several log statements in my console. console log This seems like I am not using the pipe in right approach. Could someone please shed light on this.
Upvotes: 0
Views: 213
Reputation: 1637
Impure pipes are executed on each change detection, which could be bad for performance, depending on your page. If you can, always aim for pure pipes.
Pure pipes only execute when their input values change.
Upvotes: 1