What is impure pipe in Angular? -


@pipe({name:'mypipe', pure: false}) 

i unable understand impure pipes, better pure pipes.

please explain me simple , basic example?

a pure pipe called when angular detects change in value or parameters passed pipe. impure pipe called every change detection cycle no matter whether value or parameters changes.

this relevant changes not detected angular

  • when pass array or object got content changed (but still same instance)
  • when pipe injects service access other values, angular doesn't recognize if have changed.

i these cases still want pipe executed.

you should aware impure pipes prone inefficient. example when array passed pipe filter, sort, ... work might done every time change detection runs (which quite expecially default changedetectionstrategy setting) event though array might not have changed. pipe should try recognize , example return cached results.


Comments