Whenever we create a new pipe in Angular that pipe is a pure pipe. We can also set the pipe as pure or impure explicitely by setting pure property of pipe decorator to true or false respectively.
Angular executes a pure pipe only when it detects a pure change to the input value. A pure change is either
- a change to a primitive input value (String, Number, Boolean) or
- a changed object reference (Array, Date, Object)
A pure pipe is not executed if the input to the pipe is a reference type like object and only the property values of the object has change but not the reference.
So pure pipes are fast, but using them for filtering data is not a good idea because, the filtering may not work as expected if the source data is updated without a change to the object reference.
Let's understand pure pipe with some examples in this lecture.
DOWNLOAD SECTION SOURCE CODE HERE: drive.google.c...
26 авг 2024