(changes: IterableChanges<T>)
| 284 | } |
| 285 | |
| 286 | private _applyChanges(changes: IterableChanges<T>) { |
| 287 | const viewContainer = this._viewContainer; |
| 288 | changes.forEachOperation( |
| 289 | ( |
| 290 | item: IterableChangeRecord<T>, |
| 291 | adjustedPreviousIndex: number | null, |
| 292 | currentIndex: number | null, |
| 293 | ) => { |
| 294 | if (item.previousIndex == null) { |
| 295 | // NgForOf is never "null" or "undefined" here because the differ detected |
| 296 | // that a new item needs to be inserted from the iterable. This implies that |
| 297 | // there is an iterable value for "_ngForOf". |
| 298 | viewContainer.createEmbeddedView( |
| 299 | this._template, |
| 300 | new NgForOfContext<T, U>(item.item, this._ngForOf!, -1, -1), |
| 301 | currentIndex === null ? undefined : currentIndex, |
| 302 | ); |
| 303 | } else if (currentIndex == null) { |
| 304 | viewContainer.remove(adjustedPreviousIndex === null ? undefined : adjustedPreviousIndex); |
| 305 | } else if (adjustedPreviousIndex !== null) { |
| 306 | const view = viewContainer.get(adjustedPreviousIndex)!; |
| 307 | viewContainer.move(view, currentIndex); |
| 308 | applyViewChange(view as EmbeddedViewRef<NgForOfContext<T, U>>, item); |
| 309 | } |
| 310 | }, |
| 311 | ); |
| 312 | |
| 313 | for (let i = 0, ilen = viewContainer.length; i < ilen; i++) { |
| 314 | const viewRef = <EmbeddedViewRef<NgForOfContext<T, U>>>viewContainer.get(i); |
| 315 | const context = viewRef.context; |
| 316 | context.index = i; |
| 317 | context.count = ilen; |
| 318 | context.ngForOf = this._ngForOf!; |
| 319 | } |
| 320 | |
| 321 | changes.forEachIdentityChange((record: any) => { |
| 322 | const viewRef = <EmbeddedViewRef<NgForOfContext<T, U>>>viewContainer.get(record.currentIndex); |
| 323 | applyViewChange(viewRef, record); |
| 324 | }); |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Asserts the correct type of the context for the template that `NgForOf` will render. |
no test coverage detected