Processing Action Parameter in Ember.js

In the template:

<button {{action someAction someParameter}}>Some Action</button> 

In the controller:

 someAction: function (e, someParameter) { console.log(e, someParameter); } 

someParameter is undefined, as well as e , where I am excluded as an event object.

How to pass parameter to action? If this is not possible, then I need to create Ember.View to handle the action with the parameter?

+4
source share
1 answer

The only problem that I see in your code is that the event object is not passed to the function in the controller when using the {{action}} helper . Regardless, your code should register the value of someParameter in the console. If you get two undefined , maybe someParameter not in the context of the template , or it is undefined .

Make sure someParameter exists and contains the correct value, for example:

Template:

 <button {{action someAction someParameter}}>Some Action (param: {{someParameter}} ) </button> 

If the value is not displayed, try view.someParameter depending on how the template is displayed, if you show your code, we could help you more.

On the controller:

 someAction: function (someParameter) { console.log(someParameter); } 

Hope this helps!

+9
source

All Articles