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(){ ...

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.