Template Modifying Action's first Parameter



You can modify the action's first parameter by specifying a value option for the {{action}} helper.

Syntax

<input type = "text" value = {{name}} onblur = {{action "action-name"}} />

Example

The example given below shows modifying the action's first parameter by using the {{action}} helper with value option. Create a new component and name it as post-action.js with the following code −

import Ember from 'ember';

export default Ember.Component.extend({
   actions: {
      actionFirstParameter(newName) {
         document.write('Name is:'+' '+newName);
      }
   }
});

Open the post-action.hbs file created under app/templates/ with the following code −

<label>Enter the name:</label>
<input type = "text" value = {{yourName}} onblur = 
   {{action "actionFirstParameter" value = "target.value"}} />
{{outlet}}

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

{{post-action}}
{{outlet}}

Output

Run the ember server and you will get the input box to enter the value −

Ember.js Template Modify Actions first Parameters

It will display the value of the input field, where the user has mentioned as shown in the screenshot below −

Ember.js Template Modify Actions first Parameters
emberjs_template.htm
Advertisements