(matchingTemplateIndex: number, contextValue?: T)
| 161 | * @codeGenApi |
| 162 | */ |
| 163 | export function ɵɵconditional<T>(matchingTemplateIndex: number, contextValue?: T) { |
| 164 | performanceMarkFeature('NgControlFlow'); |
| 165 | |
| 166 | const hostLView = getLView(); |
| 167 | const bindingIndex = nextBindingIndex(); |
| 168 | const prevMatchingTemplateIndex: number = |
| 169 | hostLView[bindingIndex] !== NO_CHANGE ? hostLView[bindingIndex] : -1; |
| 170 | const prevContainer = |
| 171 | prevMatchingTemplateIndex !== -1 |
| 172 | ? getLContainer(hostLView, HEADER_OFFSET + prevMatchingTemplateIndex) |
| 173 | : undefined; |
| 174 | const viewInContainerIdx = 0; |
| 175 | |
| 176 | if (bindingUpdated(hostLView, bindingIndex, matchingTemplateIndex)) { |
| 177 | const prevConsumer = setActiveConsumer(null); |
| 178 | try { |
| 179 | // The index of the view to show changed - remove the previously displayed one |
| 180 | // (it is a noop if there are no active views in a container). |
| 181 | if (prevContainer !== undefined) { |
| 182 | removeLViewFromLContainer(prevContainer, viewInContainerIdx); |
| 183 | } |
| 184 | |
| 185 | // Index -1 is a special case where none of the conditions evaluates to |
| 186 | // a truthy value and as the consequence we've got no view to show. |
| 187 | if (matchingTemplateIndex !== -1) { |
| 188 | const nextLContainerIndex = HEADER_OFFSET + matchingTemplateIndex; |
| 189 | const nextContainer = getLContainer(hostLView, nextLContainerIndex); |
| 190 | const templateTNode = getExistingTNode(hostLView[TVIEW], nextLContainerIndex); |
| 191 | |
| 192 | const dehydratedView = findAndReconcileMatchingDehydratedViews( |
| 193 | nextContainer, |
| 194 | templateTNode, |
| 195 | hostLView, |
| 196 | ); |
| 197 | const embeddedLView = createAndRenderEmbeddedLView(hostLView, templateTNode, contextValue, { |
| 198 | dehydratedView, |
| 199 | }); |
| 200 | |
| 201 | addLViewToLContainer( |
| 202 | nextContainer, |
| 203 | embeddedLView, |
| 204 | viewInContainerIdx, |
| 205 | shouldAddViewToDom(templateTNode, dehydratedView), |
| 206 | ); |
| 207 | } |
| 208 | } finally { |
| 209 | setActiveConsumer(prevConsumer); |
| 210 | } |
| 211 | } else if (prevContainer !== undefined) { |
| 212 | // We might keep displaying the same template but the actual value of the expression could have |
| 213 | // changed - re-bind in context. |
| 214 | const lView = getLViewFromLContainer<T | undefined>(prevContainer, viewInContainerIdx); |
| 215 | if (lView !== undefined) { |
| 216 | lView[CONTEXT] = contextValue; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 |
no test coverage detected
searching dependent graphs…