Skip to the workspace
Pebellslearn by building
Understand Binding  ›  Lesson

Interpolation and the Four Bindings

Interpolation 12 minData binding keeps the template and the class in sync, and interpolation with double curly braces is the simplest form, turning a template expression into text on the page.

angular / Interpolation and the Four Bindings

Explore each scene at your own pace.

01 · The rule

The rule

Interpolation and the Four Bindings

A template on its own is static HTML. Greenhouse needs the plant's name, its photo, its watering button and a nickname field to stay in step with the data in the class. Angular calls this data binding, and there are only four shapes to learn.

The rule

Curly braces print; square brackets set; round brackets listen; both do both.

Syntax Name Direction
{{ expr }} Interpolation class → template (as text)
[prop]="expr" Property binding class → template
(event)="statement" Event binding template → class
[(value)]="signal" Two-way binding both

This lesson takes the first. Interpolation evaluates a template expression and puts the result into the page as text:

<h3>{{ plant().name }}</h3>
<p>Water every {{ plant().everyDays }} days</p>
<p>Next watering in {{ plant().everyDays - daysSince() }} days</p>
<img src="/photos/{{ plant().id }}.jpg" alt="Photo of {{ plant().name }}" />

The result is converted to a string. null and undefined show as nothing rather than the word "null". Interpolation also works inside an attribute value, as in the alt above.

A template expression should be quick and free of side effects: read a signal, a property, do simple arithmetic, call a pure method. It may use the class's members, but not globals like window or console. It cannot contain assignments, and it runs every time Angular checks the view, so never make a server call or change state there.

Interpolated text is escaped. If a plant's name is <b>Fern</b>, the learner sees the tags as text; Angular will not turn data into HTML by accident.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.