If we have used function in template, it will be called many times even Input parameters are same as previous, This is because of the Change detection mechanism in Angular.
Angular cannot detect whether the result of function is changed until it runs the that function
Solution
Can we cache the result for a certain input then, next time use the same input to simply return the cached result?
The pure pipe can help us in this case.
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, Symbol) or a changed object reference (Date, Array, Function, Object)
https://dzone.com/articles/why-we-shound-not-use-function-inside-angular-temp
Angular cannot detect whether the result of function is changed until it runs the that function
Solution
Can we cache the result for a certain input then, next time use the same input to simply return the cached result?
The pure pipe can help us in this case.
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, Symbol) or a changed object reference (Date, Array, Function, Object)
No comments:
Post a Comment