O'Reilly logo

Ember.js Cookbook by Erik Hanchett

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

Handling actions in controllers

Actions are important to controllers. They are triggered by the user action and can be used to change the application state. In this recipe, we'll create four different types of actions and see how they react to different situations.

How to do it...

  1. In a new application, generate the following files:
    $ ember g controller application
    $ ember g route application
    

    We'll be using the controller and application to store actions. Some actions will bubble up to the route, and some won't.

  2. Update the application controller and add three new actions:
    // app/controllers/application.js import Ember from 'ember'; export default Ember.Controller.extend({ actions: { action1(){ alert('Application controller action action1'); }, action2(){ ...

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