O'Reilly logo

Mastering Ember.js by Mitchel Kelonye

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Registering event handlers in views

Views can register event handlers on events emitted from elements in their rendered templates, in addition to the use of the action template expressions. For example, let's reuse an example from Chapter 4, Writing Application Templates:

  <button {{action 'checkout'}}>checkout</button>

This example can easily be reimplemented as a view, as shown in the following code:

App.CheckoutButton = Ember.View.extend({
  tagName: 'button',
  click: function(event){
    this.get('controller').send('checkout');
  }
});

{{! template }}
{{#view App.CheckoutButton }}checkout{{/view}}

In this example, we created a custom button view that registers a click event handler.

Every view manages only the events invoked from their templates. However, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required