I parsed ng-repeat and extracted the attached blocks of code, seeing that they contain logic that processes the repeating algorithm (which I want to understand how it works).
I have a few questions, but since they are all about the ng-repeat internal elements, I decided to ask them all here. I see no reason to separate them into different SO questions. I am marked inline, to which the line (s) of code relates, to which each question relates.
- Why do they need to make sure
trackById not a native hasOwnProperty function? (something that this function does is assertNotHasOwnProperty , part of the Angular internal API) - As for my intuition, this code is executed on elements that are already in the repeater, when it should update the collection - it just picks them up and pushes them into the list for processing, right?
- This code block is obviously looking for duplicates in the repeater collection. But how exactly this happens is beyond me. Please explain.
- Why should Angular store the block object as
nextBlockMap and in nextBlockOrder ? - What are
block.endNode and block.startNode ? - I suppose the answer to this question will explain how this algorithm works, but please explain why it should check if
nextNode (was) '$$NG_REMOVED' ? - What's going on here? Again, I believe that question 6 will already provide an answer to this question. But still pointing to it.
As I said, I broke through ng-repeat to find code that I find relevant to the repeating mechanism. In addition, I understand the rest of the directive. So, without further ado, here is the code (from version 2.1.0):
length = nextBlockOrder.length = collectionKeys.length; for (index = 0; index < length; index++) { key = (collection === collectionKeys) ? index : collectionKeys[index]; value = collection[key]; trackById = trackByIdFn(key, value, index); // question
angularjs angularjs-ng-repeat
pilau
source share