Working with bindings

Most frameworks include some sort of binding implementation. Ember is no exception and has bindings that can be used with any object. The following recipes explain how to use them as well as one-way and two-way binding.

How to do it...

In this example, there is a teacher and student Ember object. Each has its own set of properties and they both have homeroom. We can share the homeroom by setting an alias for the teacher object.

  1. Let's begin by creating a teacher and student Ember.Object:
    const Teacher = Ember.Object.extend({
      homeroom: '',
      age: '',
      gradeTeaching: ''
    });
    
    const Student = Ember.Object.extend({
      homeroom: Ember.computed.alias('teacher.homeroom'),
      age: '',
      grade: '',
      teacher: null
    });

    The student homeroom is Ember.computed.alias ...

Get Ember.js Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.