Crash Course: The Bindable Element In Aurelia 2

In Aurelia 2, a new element called bindable has been introduced which is leveraged in HTML only custom elements. If you want a HTML only custom element which has one or more bindable properties, then you use the bindable element to specify them.

The ability to create bindables for HTML only custom elements existed in Aurelia 1, but was limited. The constraint being the bindable keyword had to be specified on the template element.

<template bindable="user">...</template>

In Aurelia 2, this now becomes something much more simple and clean because template is no longer a requirement for HTML only custom elements.

<bindable name="user" />

Besides the semantics changing, you can now also specify the binding mode for the defined variable. This was not possible in Aurelia 1 when creating HTML custom elements.

Now, simply adding a mode property and valid binding mode value, you can change how the binding works just like you can when configuring the binding mode inside of a view-model.

<bindable name="user" mode="one-way" />

One response to “Crash Course: The Bindable Element In Aurelia 2”

  1. Mark Roeling says:

    Great to read these small tutorials!

    Into Aurelia 1 for 2 years now, of course read the blogs about Aurelia 2 on, but what this all means in practice was yet to be seen without the new documentation and tbh without playing with the new code.

Leave a Reply

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