Aurelia – Data Binding


Aurelia – Data Binding


”;


Aurelia has its own data-binding system. In this chapter, you will learn how to bind data with Aurelia, and also explain the different binding mechanics.

Simple Binding

You already saw simple binding in some of our previous chapters. ${…}syntax is used to link veiw-model and view.

app.js

export class App {  
   constructor() {
      this.myData = ''Welcome to Aurelia app!'';
   }
}

app.html

<template>
   <h3>${myData}</h3>
</template>

Aurelia Data Binding Simple

Two-Way Binding

The beauty of Aurelia is in its simplicity. The two-way data binding is automatically set, when we bind to input fields

app.js

export class App {  
   constructor() {
      this.myData = ''Enter some text!'';
   }
}

app.html

<template>
   <input id = "name" type = "text" value.bind = "myData" />
   <h3>${myData}</h3>
</template>

Now, we have our view-model and view linked. Whenever we enter some text inside the input field, the view will be updated.

Aurelia Data Binding Two Way

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *