Cheat Sheet
Quick reference guide for Aurelia 2 templating syntax and common patterns.
Data Binding
Binding Modes
.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
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
switch.bind
List Rendering
Basic Syntax
Contextual Properties
$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
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
Class & Style Binding
Attribute Binding
Promises in Templates
Spread Binding
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)
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
Use appropriate binding modes:
.to-viewfor display-only dataAdd keys to repeat.for: Enables efficient DOM reuse
Use show.bind for frequent toggles: Avoids DOM manipulation overhead
Use if.bind for infrequent changes: Saves memory and resources
Debounce/throttle rapid events: Prevents excessive handler calls
Keep expressions simple: Move complex logic to view model
Use value converters: Separate formatting from view model logic
Common Gotchas
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
Related Documentation
Last updated
Was this helpful?