liveBook · Manning

forEachRemovedItem

As explained in Pro Angular 16

forEachRemovedItem is an Angular iterable-changes method that invokes a callback for each item removed from a collection.

forEachRemovedItem invokes a callback for every object removed from an iterable collection. An Angular structural directive can use it to remove the embedded view representing each deleted object. section 15.3.4

Handling a removed item requires coordinated view and context updates:

  • Find the removed item’s PaIteratorContext in a Map indexed by IterableChangeRecord.trackById. section 15.3.4
  • Pass its ViewRef to ViewContainerRef.remove so the corresponding rendered content disappears. section 15.3.4
  • Update surviving contexts with their new positions and the total number of active views. section 15.3.4

Deleting a product row

A table’s Delete button calls deleteProduct(item.id). The data model removes the product, the iterable differ reports it through forEachRemovedItem, and the directive removes the matching row. Updating surviving contexts keeps row striping and Delete-button targets correct. section 15.3.4

How Pro Angular 16 covers it

How deep it goes
Explains callback purpose and view-removal mechanics, including identity mapping and surviving-context updates.
Examples
Uses a product table whose Delete button removes a product and triggers removal of its rendered row.
What it assumes
Assumes Angular structural-directive, iterable-differ, view-container, and collection concepts.
What you can do after
Build it from scratch: implement removal handling in a custom Angular structural iterator directive.
How it connects
Connects iterable differ, IterableChangeRecord, trackBy identity, ViewRef, ViewContainerRef, and embedded views.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.