home
  • Blog
1.12
  • Getting Started
  • Concepts
  • The Object Model
  • Application
  • Templates
  • Routing
  • Components
    • Introduction
    • Defining a Component
    • Passing Properties to a Component
    • Wrapping Content in a Component
    • Customizing a Component's Element
    • Handling User Interaction with Actions
    • Sending Actions from Components to Your Application
  • Controllers
  • Models
  • Views
  • Enumerables
  • Testing
  • Configuring Ember.js
  • Ember Inspector
  • Cookbook
  • Understanding Ember.js
  • Contributing to Ember.js
Old Guides - You are viewing the guides for Ember v1.12.0.
Go to v5.0.0

Handling User Interaction with Actions

Edit pencil

Components allow you to define controls that you can reuse throughout your application. If they're generic enough, they can also be shared with others and used in multiple applications.

To make a reusable control useful, however, you first need to allow users of your application to interact with it.

You can make elements in your component interactive by using the {{action}} helper. This is the same {{action}} helper you use in application templates, but it has an important difference when used inside a component.

Instead of sending an action to the template's controller, then bubbling up the route hierarchy, actions sent from inside a component are sent directly to the component's Ember.Component instance, and do not bubble.

For example, imagine the following component that shows a post's title. When the title is clicked, the entire post body is shown:

app/templates/components/post-summary.hbs
<h3 {{action "toggleBody"}}>{{title}}</h3>
{{#if isShowingBody}}
  <p>{{{body}}}</p>
{{/if}}
app/components/post-summary.js
export default Ember.Component.extend({
  actions: {
    toggleBody: function() {
      this.toggleProperty('isShowingBody');
    }
  }
});

The {{action}} helper can accept arguments, listen for different event types, control how action bubbling occurs, and more.

For details about using the {{action}} helper, see the Actions section of the Templates chapter.

left arrow
Customizing a Component's Element
Sending Actions from Components to Your Application
right arrow
Team Sponsors Security Legal Branding Community Guidelines
Twitter GitHub Discord Mastodon

If you want help you can contact us by email, open an issue, or get realtime help by joining the Ember Discord.

© Copyright 2023 - Tilde Inc.
Ember.js is free, open source and always will be.


Ember is generously supported by
blue