Reactivity

Declare state

logo of Aurelia 2 Aurelia 2

<h1>Hello ${name}</h1>

logo of Aurelia 1 Aurelia 1

<template>
  <h1>Hello ${name}</h1>
</template>

Update state

logo of Aurelia 2 Aurelia 2

<h1>Hello ${name}</h1>

logo of Aurelia 1 Aurelia 1

<template>
  <h1>Hello ${name}</h1>
</template>

Computed state

logo of Aurelia 2 Aurelia 2

<div>${doubleCount}</div>

logo of Aurelia 1 Aurelia 1

<template>
  <div>${doubleCount}</div>
</template>

Templating

Minimal template

logo of Aurelia 2 Aurelia 2

<h1>Hello world</h1>

logo of Aurelia 1 Aurelia 1

<template>
  <h1>Hello world</h1>
</template>

Styling

logo of Aurelia 2 Aurelia 2

.title {
  color: red;
}

logo of Aurelia 1 Aurelia 1

.title {
  color: red;
}

Loop

logo of Aurelia 2 Aurelia 2

<ul>
  <li repeat.for="color of colors">${color}</li>
</ul>

logo of Aurelia 1 Aurelia 1

<template>
  <ul>
    <li repeat.for="color of colors">${color}</li>
  </ul>
</template>

Event click

logo of Aurelia 2 Aurelia 2

<p>Counter: ${count}</p>
<button click.trigger="incrementCount">+1</button>

logo of Aurelia 1 Aurelia 1

<template>
  <p>Counter: ${count}</p>
  <button click.trigger="incrementCount()">+1</button>
</template>

Dom ref

logo of Aurelia 2 Aurelia 2

<input ref="inputElement" />

logo of Aurelia 1 Aurelia 1

<template>
  <input ref="inputElement" />
</template>

Conditional

logo of Aurelia 2 Aurelia 2

<button click.trigger="nextLight()">Next light</button>
<p>Light is: ${light}</p>
<p switch.bind="light">
  You must
  <span case="red">STOP</span>
  <span case="orange">SLOW DOWN</span>
  <span case="green">GO</span>
</p>

logo of Aurelia 1 Aurelia 1

<template>
  <button click.trigger="nextLight()">Next light</button>
  <p>Light is: ${light}</p>
  <p>
    You must
    <span if.bind="light === 'red'">STOP</span>
    <span if.bind="light === 'orange'">SLOW DOWN</span>
    <span if.bind="light === 'green'">GO</span>
  </p>
</template>

Lifecycle

On mount

logo of Aurelia 2 Aurelia 2

<p>Page title is: ${pageTitle}</p>

logo of Aurelia 1 Aurelia 1

<template>
  <p>Page title is: ${pageTitle}</p>
</template>

On unmount

logo of Aurelia 2 Aurelia 2

<p>Current time: ${time}</p>

logo of Aurelia 1 Aurelia 1

<template>
  <p>Current time: ${time}</p>
</template>

Component composition

Props

logo of Aurelia 2 Aurelia 2

<user-profile
  name.bind
  age.bind
  favourite-colors.bind="colors"
  is-available.bind="available"
></user-profile>

logo of Aurelia 1 Aurelia 1

<template>
  <require from="./user-profile"></require>
  <user-profile
    name.bind="name"
    age.bind="age"
    favourite-colors.bind="colors"
    is-available.bind="available"
  ></user-profile>
</template>

Emit to parent

logo of Aurelia 2 Aurelia 2

<p>Can I come ?</p>
<answer-button action-handler.bind="handleAnswer"></answer-button>
<p style="font-size: 50px">${isHappy ? "😀" : "😥"}</p>

logo of Aurelia 1 Aurelia 1

<template>
  <require from="./answer-button"></require>
  <p>Can I come ?</p>
  <answer-button action-handler.call="handleAnswer(reply)"></answer-button>
  <p style="font-size: 50px">${isHappy ? "😀" : "😥"}</p>
</template>

Slot

logo of Aurelia 2 Aurelia 2

<funny-button>Click me !</funny-button>

logo of Aurelia 1 Aurelia 1

<template>
  <require from="./funny-button"></require>

  <funny-button>Click me !</funny-button>
</template>

Slot fallback

logo of Aurelia 2 Aurelia 2

<funny-button></funny-button>
<funny-button>Click me !</funny-button>

logo of Aurelia 1 Aurelia 1

<template>
  <require from="./funny-button"></require>

  <funny-button></funny-button>
  <funny-button>Click me !</funny-button>
</template>

Context

logo of Aurelia 2 Aurelia 2

<h1>Welcome back, {{ user.username }}</h1>
<user-profile />

logo of Aurelia 1 Aurelia 1

Missing snippet Help us to improve Component Party logo

Form input

Input text

logo of Aurelia 2 Aurelia 2

<p>${text}</p>
<input value.bind />

logo of Aurelia 1 Aurelia 1

<template>
  <p>${text}</p>
  <input value.bind="text" />
</template>

Checkbox

logo of Aurelia 2 Aurelia 2

<input id="is-available" type="checkbox" checked.bind="isAvailable" />
<label for="is-available">Is available</label>: ${isAvailable}

logo of Aurelia 1 Aurelia 1

<template>
  <input id="is-available" type="checkbox" checked.bind="isAvailable" />
  <label for="is-available">Is available</label>: ${isAvailable}
</template>

Radio

logo of Aurelia 2 Aurelia 2

<div>Picked: ${picked}</div>

<input id="blue-pill" checked.bind="picked" type="radio" value="blue" />
<label for="blue-pill">Blue pill</label>

<input id="red-pill" checked.bind="picked" type="radio" value="red" />
<label for="red-pill">Red pill</label>

logo of Aurelia 1 Aurelia 1

<template>
  <div>Picked: ${picked}</div>

  <input id="blue-pill" checked.bind="picked" type="radio" value="blue" />
  <label for="blue-pill">Blue pill</label>

  <input id="red-pill" checked.bind="picked" type="radio" value="red" />
  <label for="red-pill">Red pill</label>
</template>

Select

logo of Aurelia 2 Aurelia 2

<select value.bind="selectedColorId">
  <option value="">Select A Color</option>
  <option
    repeat.for="color of colors"
    value.bind="color.id"
    disabled.bind="color.isDisabled"
  >
    ${color.text}
  </option>
</select>

logo of Aurelia 1 Aurelia 1

<template>
  <select value.bind="selectedColorId">
    <option value="">Select A Color</option>
    <option
      repeat.for="color of colors"
      value.bind="color.id"
      disabled.bind="color.isDisabled"
    >
      ${color.text}
    </option>
  </select>
</template>

Webapp features

Render app

logo of Aurelia 2 Aurelia 2

<!doctype html>
<html>
  <head>
    <script type="module" src="./main.ts"></script>
  </head>

  <body>
    <app></app>
  </body>
</html>

logo of Aurelia 1 Aurelia 1

Missing snippet Help us to improve Component Party logo

Fetch data

logo of Aurelia 2 Aurelia 2

<template promise.bind="useFetchUsers.fetchData()">
  <p pending>Fetching users...</p>
  <p catch>An error ocurred while fetching users</p>
  <ul then.from-view="users">
    <li repeat.for="user of users">
      <img src.bind="user.picture.thumbnail" alt="user" />
      <p>${ user.name.first } ${ user.name.last }</p>
    </li>
  </ul>
</template>

logo of Aurelia 1 Aurelia 1

<template>
  <p if.bind="isLoading">Fetching users...</p>
  <p if.bind="error">An error ocurred while fetching users</p>
  <ul if.bind="users">
    <li repeat.for="user of users">
      <img src.bind="user.picture.thumbnail" alt="user" />
      <p>${ user.name.first } ${ user.name.last }</p>
    </li>
  </ul>
</template>