How to get normalized values for an array when using ng-repeat

我的梦境 提交于 2019-12-06 15:28:38

ngRepeat directive is not happy. Your code creates new objects each time. Digestion loops over and over again...

From what I know, the track by expression is not supposed to make angular match the previous entities with the corresponding new ones after you erased all their internal $$hashKey properties by recreating the entities. This instruction is designed to tell ngRepeat directive how to build this internal $$hashKey to avoid DOM element creation waste.

So .. You may only alter your items instead of creating new ones:

    groupItems.forEach(function (item) {
        item.normalizedValue = item.value / maxValue;
    });
    return groupItems;

And then it works.

Moreover, your filtering is happening at each digest loop. For performance purposes, you may prefer bake this array in specific events/watchers callbacks.

UPDATE

Actually, digestion won't loop over and over again if you bake this list outside of the ngRepeat expression ! I suggest you to have a controller per group using the child scopes created by the ngRepeat directive and bake this list in a watcher callback.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!