Chapter 5. Value converters and binding behaviors

 

This chapter covers

  • Creating and using simple value converters
  • Exploring advanced value converters with parameters
  • Understanding value-converter composition
  • Using Aurelia’s built-in binding behaviors

So far, the binding expressions that we’ve looked at have taken a value from the view-model and rendered it out to the view. But what happens if the value in the view-model isn’t suitable for display? For example, if you’ve got a UTC date in your view-model, you’d most likely want to transform this in some way so that it would be suitable to display in the view. Conversely, you might want to transform a local date entered by the user back to UTC format on the way back into the view-model.

Value converters are Aurelia view resources responsible for doing this. What if you need to control when a binding notification is delivered from the view to the view-model? For example, imagine you have an input field bound to a view-model property, and you want only the view-model property to be updated when the user has finished typing in the field? Binding behaviors allow you to hook into the Aurelia binding system and change the way bindings behave to suit your needs, in a plethora of scenarios. In this chapter, you’ll learn how to use value converters and binding behaviors to gain ultimate control over your Aurelia views.

5.1. Creating a value converter

5.2. Applying value converters to lists

5.3. Binding behaviors

5.4. my-books project status

Summary