Reputation:
Angular Impure pipes should not be used , but if we use it then there could be a performance hit since they are executed for any component change detection cycle .
Could any tell me any scenario where using impure pipe is the only solution or using it is best ?
Upvotes: 2
Views: 444
Reputation: 12508
If we take a look at Angular's own internal pipes that are impure, they are :
All of these are impure because they take some sort of object type as the input param, so the typical change detection from pure pipes doesn't kick off the pipe. Makes sense.
But on top of that, atleast two of these are used for debugging purposes mainly (JSONPipe, KeyValuePipe), and slice... well.. I'm not that fond of it but it's atleast a lightweight pipe.
The key ingredients when doing an impure pipe IMO are
Documentation :
Upvotes: 0
Reputation: 405
When the output if the pipe is dependent on external values besides the input arguments of the pipe.
E.g. when you have a pipe that pretty prints a date:
... etc.
The pipe depends on the current date. So if it is 23:59 and 2 more minutes pass so it is 00:01 of the next day, the pipe needs to be updated. The same input parameter yields other output
Upvotes: 2
Reputation: 464
An impure pipe kind of pipes that trigger changes in the value or parameters, the best example for using it is the Google Translator for example, it triggers the user input and translates to the specified destination language
Upvotes: 0