liveBook · Manning

Implicit value

As explained in Pro Angular 16

The $implicit property is the default value property on an Angular template context object for a structural directive.

The implicit value is the default value exposed by a structural directive’s template context. A directive places the current item in the context object’s $implicit property; the template names that value with let-item and can then use item in bindings. section 15.3

Binding the current item

In <ng-template [paForOf]="products()" let-item>, each iteration assigns the current product to item. The binding {{item.name}} displays that product’s name. The let-item declaration creates the variable name; it does not assign an expression itself. section 15.3

A custom iterator supplies the value by constructing a context object with a $implicit property and passing it to createEmbeddedView. The same context can expose named properties such as index, odd, even, first, and last. section 15.3.1

Use implicit and named context values together:

  • Use let-item for the default current object. section 15.3
  • Keep the context contract aligned with the variables consumed by the template. section 15.3.1

How Pro Angular 16 covers it

How deep it goes
Explains template naming and context-object implementation, while stopping short of broader Angular template compilation internals.
Examples
Demonstrates paForOf iterating products, displaying item.name, and adding index, odd, and even values to table rows.
What it assumes
Assumes basic Angular templates and bindings, while showing the structural-directive context mechanism directly through examples.
What you can do after
Build it from scratch by exposing $implicit in a directive context and consuming it with let-name in an embedded template.
How it connects
Connects implicit values with structural directives, template variables, embedded views, and ngFor-style context data.

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.