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

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

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

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , 8 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.

Related Threads:

How to add `action` to component element in ember.js?
How to add action to map area in ember.js?
How to add a parameter to a url using .htaccess without breaking in wordpress?
How call action in action in vuex?
How to add a class in ember.js?
How to add meta tag in ember.js?