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, to-view otherwise)

Default choice for most scenarios

.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

Available Key Modifiers

Category
Modifiers

Meta keys

ctrl, alt, shift, meta

Special keys

enter, escape, space, tab

Arrow keys

arrowup, arrowdown, arrowleft, arrowright

Letters

a-z (case-insensitive)

Numbers

0-9

Event control

prevent, stop

Mouse buttons

left, middle, right

Combine with +: keydown.trigger:ctrl+shift+enter="handler()"

Binding Behaviors

Conditional Rendering

if.bind vs show.bind vs hide.bind

Feature

if.bind

show.bind / hide.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

hide.bind is an alias for show.bind with inverted logic. hide.bind="true" is equivalent to show.bind="false".

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

Ref Type
Returns
Use Case

ref

HTMLElement

DOM manipulation

component.ref

View model instance

Call component methods

controller.ref

Controller instance

Advanced lifecycle access

my-attr.ref

Custom attribute instance

Access attribute methods

Template Variables

By default, <let> creates template-local variables. Add to-binding-context to assign values directly to the view model instead.

Class & Style Binding

Attribute Binding

Promises in Templates

Spread Binding

Spread binding is always one-way (to-view). Only properties that exist in the object at evaluation time create bindings.

Custom Attributes

Component Import & Usage

Dynamic Composition

Focus Management

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

Component Lifecycle (Quick Reference)

Hook
When Called
Common Use

constructor

Instance created

Inject dependencies with resolve()

created

After constructor

Access $controller

binding

Before bindings evaluated

Initialize from bindables

bound

Bindings connected

Setup dependent on bound values

attaching

Before DOM attachment

Async setup work

attached

In DOM

DOM manipulation, third-party libs

detaching

Before DOM removal

Cleanup, save state

unbinding

Bindings disconnecting

Cleanup subscriptions

Performance Tips

  1. Use appropriate binding modes: .to-view 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

Common Gotchas

Issue
Problem
Solution

Binding not updating

Object/array mutation

Use splice(), reassign, or use observable

Event not firing

Wrong event name

Check: click.trigger not onclick.trigger

Style not applied

CSS property name

Use kebab-case: background-color not backgroundColor

Async data undefined

Template renders before data

Use promise.bind or if.bind="data"

$parent undefined

Not in a repeat

Only available inside repeat.for

Accessibility Reminders

Last updated

Was this helpful?