* Locates the component within the given LView and returns the matching index
(lView: LView, componentInstance: {})
| 248 | * Locates the component within the given LView and returns the matching index |
| 249 | */ |
| 250 | function findViaComponent(lView: LView, componentInstance: {}): number { |
| 251 | const componentIndices = lView[TVIEW].components; |
| 252 | if (componentIndices) { |
| 253 | for (let i = 0; i < componentIndices.length; i++) { |
| 254 | const elementComponentIndex = componentIndices[i]; |
| 255 | const componentView = getComponentLViewByIndex(elementComponentIndex, lView); |
| 256 | if (componentView[CONTEXT] === componentInstance) { |
| 257 | return elementComponentIndex; |
| 258 | } |
| 259 | } |
| 260 | } else { |
| 261 | const rootComponentView = getComponentLViewByIndex(HEADER_OFFSET, lView); |
| 262 | const rootComponent = rootComponentView[CONTEXT]; |
| 263 | if (rootComponent === componentInstance) { |
| 264 | // we are dealing with the root element here therefore we know that the |
| 265 | // element is the very first element after the HEADER data in the lView |
| 266 | return HEADER_OFFSET; |
| 267 | } |
| 268 | } |
| 269 | return -1; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Locates the directive within the given LView and returns the matching index |
no test coverage detected