( tView: TView, lView: LView, index: number, checkNoChangesMode: boolean, )
| 51 | } |
| 52 | |
| 53 | export function selectIndexInternal( |
| 54 | tView: TView, |
| 55 | lView: LView, |
| 56 | index: number, |
| 57 | checkNoChangesMode: boolean, |
| 58 | ) { |
| 59 | ngDevMode && assertIndexInDeclRange(lView[TVIEW], index); |
| 60 | |
| 61 | // Flush the initial hooks for elements in the view that have been added up to this point. |
| 62 | // PERF WARNING: do NOT extract this to a separate function without running benchmarks |
| 63 | if (!checkNoChangesMode) { |
| 64 | const hooksInitPhaseCompleted = |
| 65 | (lView[FLAGS] & LViewFlags.InitPhaseStateMask) === InitPhaseState.InitPhaseCompleted; |
| 66 | if (hooksInitPhaseCompleted) { |
| 67 | const preOrderCheckHooks = tView.preOrderCheckHooks; |
| 68 | if (preOrderCheckHooks !== null) { |
| 69 | executeCheckHooks(lView, preOrderCheckHooks, index); |
| 70 | } |
| 71 | } else { |
| 72 | const preOrderHooks = tView.preOrderHooks; |
| 73 | if (preOrderHooks !== null) { |
| 74 | executeInitAndCheckHooks(lView, preOrderHooks, InitPhaseState.OnInitHooksToBeRun, index); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // We must set the selected index *after* running the hooks, because hooks may have side-effects |
| 80 | // that cause other template functions to run, thus updating the selected index, which is global |
| 81 | // state. If we run `setSelectedIndex` *before* we run the hooks, in some cases the selected index |
| 82 | // will be altered by the time we leave the `ɵɵadvance` instruction. |
| 83 | setSelectedIndex(index); |
| 84 | } |
no test coverage detected
searching dependent graphs…