- EmberJS Tutorial
- 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
- EmberJS Useful Resources
- EmberJS - Quick Guide
- EmberJS - Useful Resources
- EmberJS - Discussion
EmberJS - Template Action Parameter
The arguments can be passed to an action handler with the help of {{action}} helper. These values passed with this helper will be passed as arguments to the helper.
Syntax
<button {{action "action-name" argument}}>Click</button>
Example
The example given below shows passing arguments to the action handler. Create a new route and name it as actionparam.js with the following code −
import Ember from 'ember'; export default Ember.Route.extend ({ actions: { //passing the 'user' as parameter to the User function User: function (user) { document.write('Welcome.. To Tutorialspoint'); } } });
Open the actionparam.hbs file created under app/templates/ with the following code −
//passing the 'user' as parameter to a button <button {{action "User" user}}>Click Here </button> {{outlet}}
Output
Run the ember server; you will receive the following output −
Now you click on the button, the User action handler will be called with an argument containing the "user" model. This further displays the following result −
emberjs_template.htm
Advertisements