Framework Comparisons

See how Aurelia's elegant syntax compares to other popular frameworks and libraries. This is just a basic comparison, but it should give you a good idea of how Aurelia compares to other frameworks and libraries.

Conditional Rendering

Conditional rendering allows you to render different content based on the state of your application.

<!-- Simple if binding -->
<div if.bind="isVisible">Hello World</div>

<!-- If/else rendering -->
<div if.bind="isAuthenticated">
  Welcome back, ${username}!
</div>
<div else>
  Please log in
</div>

Two-way Binding

Two-way binding allows you to bind a property to an input element and have the property update when the input changes.

<!-- Two-way binding -->
<input type="text" value.bind="username">
<p>Hello, ${username}!</p>

List Rendering

List rendering allows you to render a list of items.

<!-- List rendering with repeat.for -->
<ul>
  <li repeat.for="item of items">${item}</li>
</ul>

Event Handling

Event handling allows you to handle events from the DOM.

<!-- Simple click event -->
<button click.trigger="handleClick()">Click me</button>

<!-- Event with parameter -->
<button click.trigger="handleClick($event)">With Event</button>

<!-- Key events -->
<input keyup.trigger="handleKeyUp($event)">

Class & Style Binding

Class and style binding allows you to bind classes and styles to an element.

<!-- Class binding -->
<div class.bind="dynamicClass">Dynamic class</div>
<div class="${condition ? 'active' : 'inactive'}">Conditional</div>

<!-- Style binding -->
<div style.bind="dynamicStyles">Dynamic styles</div>
<div style="color: ${textColor}">Dynamic color</div>

Component Creation

Component creation allows you to create a new component.

// my-component.ts
@customElement({
  name: 'my-component',
  template: `
    <h1>\${message}</h1>
    <button click.trigger="sayHello()">Greet</button>
  `
})
export class MyComponent {
  message = 'Hello World';
  
  @bindable name: string;
  
  sayHello() {
    console.log(`Hello ${this.name}!`);
  }
}

Computed Properties

Computed properties are properties that are derived from other properties. They are cached and only re-evaluated when their dependencies change.

export class MyComponent {
  firstName = 'John';
  lastName = 'Doe';
  
  get fullName() {
    return `${this.firstName} ${this.lastName}`;
  }
}

<!-- Template -->
<div>${fullName}</div>

Template References

Template references allow you to reference elements in the template from the component definition without needing to query the DOM.

<!-- Template reference -->
<input ref="nameInput" type="text">
<button click.trigger="focusInput()">Focus</button>

// Component class
export class MyComponent {
  nameInput: HTMLInputElement;
  
  focusInput() {
    this.nameInput.focus();
  }
}