liveBook · Manning

Model function

As explained in Modern Angular

A model signal is an Angular signal that also acts as an input and emits changed values to support two-way binding.

Angular’s model function creates a model signal: a signal that acts as both a component input and output. When its value changes, Angular emits the new value to the parent, allowing two-way binding without manually pairing input and output properties. section 10.3.4

Before model signals, a two-way-bindable property conventionally required an @Input plus an @Output named with the Change suffix. Templates could then use Angular’s two-way-binding syntax, but component code had to maintain both sides of that contract. section 10.3.4

Declare a model property

Use model() for a property that must receive a value from a parent and report updates back through the same two-way-binding pattern: property = model(); The parent can bind with [(property)]="someProperty". section 10.3.4

Model signals arrived in Angular v17.2. They replace the older pairing where property was declared as an input and propertyChange as an EventEmitter output, while preserving familiar template binding syntax. section 7.5.2 section 10.3.4

property = model();

A minimal model() declaration shows the component-side replacement for a conventional input/output pair. section 10.3.4

How Modern Angular covers it

How deep it goes
Defines model signals and contrasts them with @Input/@Output pairing without detailing update implementation internals.
Examples
Shows a property = model() declaration alongside legacy property/propertyChange declarations and [(property)] template syntax.
What it assumes
Builds on familiarity with signals and the conventional @Input/@Output two-way-binding pattern.
What you can do after
Apply it via Angular’s model function to expose a signal as a two-way-bound component property.
How it connects
Connects signals with two-way binding, @Input, @Output, EventEmitter, and Angular template binding syntax.

Related concepts

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