* Inserts a view into a container. * * This adds the view to the container's array of active views in the correct * position. It also adds the view's elements to the DOM if the container isn't a * root node of another view (in that case, the view's elements will be added when * the container's
(tView: TView, lView: LView, lContainer: LContainer, index: number)
| 192 | * @param index Which index in the container to insert the child view into |
| 193 | */ |
| 194 | function insertView(tView: TView, lView: LView, lContainer: LContainer, index: number) { |
| 195 | ngDevMode && assertLView(lView); |
| 196 | ngDevMode && assertLContainer(lContainer); |
| 197 | const indexInContainer = CONTAINER_HEADER_OFFSET + index; |
| 198 | const containerLength = lContainer.length; |
| 199 | |
| 200 | if (index > 0) { |
| 201 | // This is a new view, we need to add it to the children. |
| 202 | lContainer[indexInContainer - 1][NEXT] = lView; |
| 203 | } |
| 204 | if (index < containerLength - CONTAINER_HEADER_OFFSET) { |
| 205 | lView[NEXT] = lContainer[indexInContainer]; |
| 206 | addToArray(lContainer, CONTAINER_HEADER_OFFSET + index, lView); |
| 207 | } else { |
| 208 | lContainer.push(lView); |
| 209 | lView[NEXT] = null; |
| 210 | } |
| 211 | |
| 212 | lView[PARENT] = lContainer; |
| 213 | |
| 214 | // track views where declaration and insertion points are different |
| 215 | const declarationLContainer = lView[DECLARATION_LCONTAINER]; |
| 216 | if (declarationLContainer !== null && lContainer !== declarationLContainer) { |
| 217 | trackMovedView(declarationLContainer, lView); |
| 218 | } |
| 219 | |
| 220 | // notify query that a new view has been added |
| 221 | const lQueries = lView[QUERIES]; |
| 222 | if (lQueries !== null) { |
| 223 | lQueries.insertView(tView); |
| 224 | } |
| 225 | |
| 226 | updateAncestorTraversalFlagsOnAttach(lView); |
| 227 | // Sets the attached flag |
| 228 | lView[FLAGS] |= LViewFlags.Attached; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Track views created from the declaration container (TemplateRef) and inserted into a |
no test coverage detected
searching dependent graphs…