Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 Custom filter Pipe runs multiple times?

Tags:

angular

I have made myself a custom pipe for filtering through my own objects, that is working properly when used with my dropdown selector. But I have noticed the filter gets run multiple times, by logging through the console everytime it runs.

Basic setup is a dropdown menu with elements, and then a list of objects that contain those elements. OnInit of my component I set the default selection for the dropdown. Any idea why my Filter will be running multiple times?

Even though it is working properly it is interfering with another filter because of it running multiple times.

like image 526
johntzan Avatar asked Sep 06 '16 23:09

johntzan


1 Answers

If the pipe is pure (default) the pipe gets called when the input value or a parameter for the pipe has changed.

If the pipe is impure @Pipe({name: 'xxx', pure: false}), then the pipe is called every time change detection runs (which is usually quite often).

like image 173
Günter Zöchbauer Avatar answered Oct 10 '22 13:10

Günter Zöchbauer