johntzan
johntzan

Reputation: 323

Angular2 Custom filter Pipe runs multiple times?

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.

Upvotes: 14

Views: 5495

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657691

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).

Upvotes: 23

Related Questions