Template Action Specifying Type of Event

  • Post author:
  • Post category:EmberJS
  • Post comments:1 Comment
alternative 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 Adglob</h2>
{{/if}}
{{outlet}}

Next, open the application.hbs file created under app/templates/ with the following code −

{{post-action title = "Click Me"}}
{{outlet}}

Previous Page:-Click Here

This Post Has One Comment

Leave a Reply