In template:
<button {{action someAction someParameter}}>Some Action</button>
In controller:
someAction: function (e, someParameter) {
console.log(e, someParameter);
}
someParameter
is undefined as well as e
where I excepted to be event object.
How to pass parameter to action? If not possible does it mean I need to create Ember.View
to handle action with parameter?
The only problem 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 of that, your code should log the value of someParameter
to the console. If you are getting two undefined
maybe someParameter
is not within the context of the template, or it is undefined
.
Make sure someParameter
is there and holds the correct value, for example:
Template:
<button {{action someAction someParameter}}>Some Action (param: {{someParameter}} ) </button>
If the value doesn't show up, try view.someParameter
depending on how you are rendering the template, if you show your code we might be able to help you more.
On the controller:
someAction: function (someParameter) {
console.log(someParameter);
}
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With