- EmberJS - Home
- EmberJS - Overview
- EmberJS - Installation
- EmberJS - Core Concepts
- Creating and Running Application
- EmberJS - Object Model
- EmberJS - Router
- EmberJS - Templates
- EmberJS - Components
- EmberJS - Models
- EmberJS - Managing Dependencies
- EmberJS - Application Concerns
- EmberJS - Configuring Ember.js
- EmberJS - Ember Inspector
Template Action Specifying Type of Event
The alternative event can be specified on {{action}} helper by using the on option.
Syntax
<button {{action "action-name" on = "event-name"}}>Click</button>
Example
The example given below specifies an alternative event on the {{action}} helper. Create a new route and name it as post-action.js with the following code −
import Ember from 'ember';
export default Ember.Component.extend ({
actions: {
//toggling the text
toggleBody: function () {
this.toggleProperty('isShowing');
}
}
});
Open the post-action.hbs file created under app/templates/ with the following code −
<button {{action "toggleBody" on = 'click'}}>{{title}}</button>
{{#if isShowing}}
<h2>Welcome to TutorialsPoint</h2>
{{/if}}
{{outlet}}
Next, open the application.hbs file created under app/templates/ with the following code −
{{post-action title = "Click Me"}}
{{outlet}}
Output
Run the ember server; you will receive the following output −
Next, click on the button, the {{action}} helper triggers the action on the specified element and displays the following result −
emberjs_template.htm
Advertisements