MCPcopy Index your code
hub / github.com/angular/angular / insertView

Function insertView

packages/core/src/render3/view/container.ts:194–229  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

192 * @param index Which index in the container to insert the child view into
193 */
194function 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

Callers 1

addLViewToLContainerFunction · 0.85

Calls 7

assertLViewFunction · 0.90
assertLContainerFunction · 0.90
addToArrayFunction · 0.90
trackMovedViewFunction · 0.85
insertViewMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…