Understanding how angular ng-repeat works with arrays

Dear, I went through a question where the accepted answers suggested using a filter with ng-repeat, which mainly uses the lodash chunk function along with the memoize function. The author describes the reason for using memoize after

Many people prefer to do this in a view using a filter. It is possible, but it should be used only for display! If you add input to this filtered view, it will cause problems that can be resolved, but are not pretty or reliable.

The problem with this filter is that it returns new nested arrays every time. Angular monitors the return value from the filter.

The first time the filter runs, Angular knows the value, then starts it again to make sure that it is done. If both values ​​are the same, the cycle has ended.

If not, the filter will fire again and again until they become the same, or Angular is implemented, and an infinite digest cycle happens and goes off.

Since the new nested arrays / objects were not previously tracked by Angular, it always sees a return value that is different from the previous one.

To fix these “erratic” filters, you must wrap the filter in a function memoize.

lodashhas a function memoize, and the latest version lodashalso includes a function chunk, so we can create this filter very simply using modules npmand compile a script with browserifyor webpack.

- , memoize ng-repeat ?

+4
1

, .filter('chunk', func) angular, :

< > " , " chunk", , , :

param1: the array on which it was applied.
param2: the part after ':' 

"

, , .

, , , . , , , chunk e.t.c...

memoize, : " ( ), ".

, :

. memoize , . .
+1

Source: https://habr.com/ru/post/1606233/


All Articles