Cheat Sheet

Quick reference guide for Aurelia 2 templating syntax and common patterns.

Data Binding

Binding Modes

Syntax
Direction
Use Case

.bind

Auto (two-way for form elements, one-way otherwise)

Default choice for most scenarios

.one-way / .to-view

View Model → View

Display-only data (performance)

.two-way

View Model ↔ View

Form inputs requiring sync

.from-view

View → View Model

Capture user input only

.one-time

View Model → View (once)

Static data that never changes

Common Bindings

<!-- Text & Attributes -->
<div title.bind="tooltip">${message}</div>
<img src.bind="imageUrl" alt.bind="altText">

<!-- Form Inputs -->
<input value.bind="name">
<input value.two-way="email">
<textarea value.bind="comments"></textarea>

<!-- Boolean Attributes -->
<button disabled.bind="isLoading">Submit</button>
<input required.bind="isRequired">

<!-- Checkboxes -->
<input type="checkbox" checked.bind="isActive">
<input type="checkbox" model.bind="item.id" checked.bind="selectedIds">

<!-- Radio Buttons -->
<input type="radio" model.bind="option1" checked.bind="selectedOption">
<input type="radio" model.bind="option2" checked.bind="selectedOption">

<!-- Select -->
<select value.bind="selectedValue">
  <option repeat.for="opt of options" value.bind="opt.id">${opt.name}</option>
</select>

String Interpolation

Event Binding

Basic Events

Event Modifiers

Binding Behaviors

Conditional Rendering

if.bind vs show.bind

Feature

if.bind

show.bind

DOM Manipulation

Adds/removes from DOM

Shows/hides (display: none)

Performance

Better for infrequent changes

Better for frequent toggles

Resources

Cleans up events/bindings

Keeps everything in memory

Use When

Content rarely changes

Content toggles frequently

switch.bind

List Rendering

Basic Syntax

Contextual Properties

Property
Type
Description

$index

number

Zero-based index (0, 1, 2...)

$first

boolean

True for first item

$last

boolean

True for last item

$middle

boolean

True for middle items

$even

boolean

True for even indices

$odd

boolean

True for odd indices

$length

number

Total number of items

$parent

object

Parent binding context

$previous

any

Previous item (when contextual enabled)

Advanced Collection Types

Value Converters

Syntax

Common Built-in Patterns

Template References

Template Variables

Class & Style Binding

Promises in Templates

Custom Attributes

Component Import & Usage

Quick Decision Trees

When to use if vs show?

Which binding mode?

When to use keys in repeat.for?

Common Patterns

Loading States

Form Validation Display

Computed Display Values

Dynamic CSS Classes

Performance Tips

  1. Use appropriate binding modes: .one-way for display-only data

  2. Add keys to repeat.for: Enables efficient DOM reuse

  3. Use show.bind for frequent toggles: Avoids DOM manipulation overhead

  4. Use if.bind for infrequent changes: Saves memory and resources

  5. Debounce/throttle rapid events: Prevents excessive handler calls

  6. Keep expressions simple: Move complex logic to view model

  7. Use value converters: Separate formatting from view model logic

Accessibility Reminders

Last updated

Was this helpful?