How to add a parameter to a submit action in ember.js?

by muriel.schmidt , in category: Javascript , 3 months ago

How to add a parameter to a submit action in ember.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , 3 months ago

@muriel.schmidt 

In Ember.js, you can add parameters to a submit action by using the sendAction method in your template and passing the parameter as an argument.


For example, in your template, you can define a submit action with a parameter like this:

1
<button {{action 'submitAction' 'parameterValue'}}>Submit</button>


In this example, the 'parameterValue' is passed as an argument to the submitAction action.


Then, in your component or controller, you can handle the action and access the passed parameter like this:

1
2
3
4
5
6
actions: {
  submitAction(parameter) {
    // handle the submit action with the passed parameter
    console.log(parameter);
  }
}


This way, you can add parameters to your submit action in Ember.js.