# Passing parameter

**URL:** <https://discuss.emberjs.com/t/passing-parameter/14608>\
**Category:** Uncategorized\
**Created:** [April 22, 2018, 7:08pm UTC](https://discuss.emberjs.com/t/passing-parameter/14608 "2018-04-22T19:08:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![akhil\_ck](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@akhil\_ck](https://discuss.emberjs.com/u/akhil_ck)\
**Post date:** [April 22, 2018, 7:08pm UTC](https://discuss.emberjs.com/t/passing-parameter/14608/1 "2018-04-22T19:08:58Z")

</div>

Hi guys, i have two buttons so when i click each button i should know which button i have clicked so how can i do it in ember js (button is not component type just normal button

---

<div class="post-metadata">

**Author:** ![Havremunken](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/havremunken/32/12065_2.png) [@Havremunken](https://discuss.emberjs.com/u/Havremunken)\
**Post date:** [April 23, 2018, 5:56am UTC](https://discuss.emberjs.com/t/passing-parameter/14608/2 "2018-04-23T05:56:48Z")

</div>

I don’t know if it is THE correct way to do it, but one relatively simple way would of course be to create a component out of it. If you just let ember cli generate the component for you, you can easily pass in some value to the component as you use it in your templates.

```
{{#my-button param="firstButton"}}First button{{/my-button}}
{{#my-button param="secondButton"}}Second button{{/my-button}}

```

In the component code you can then just do something like

`var passedParam = this.get('param');`

in an action to get the value. Of course, I don’t know if this is the correct way to go in your situation, but it could be a starting point.

Disclaimer: I am pretty much a newbie myself, but I’ve done something similar a few times.

---

<div class="post-metadata">

**Author:** ![alexspeller](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/alexspeller/32/14812_2.png) [@alexspeller](https://discuss.emberjs.com/u/alexspeller)\
**Post date:** [April 23, 2018, 1:27pm UTC](https://discuss.emberjs.com/t/passing-parameter/14608/3 "2018-04-23T13:27:20Z")

</div>

There is no need to create a component here.

Either send a different action from each button, or use a different argument for each action.

```auto
<button {{action 'action1'}}>Button 1</button>
<button {{action 'action2'}}>Button 2</button>

```

or

```auto
<button {{action 'action' 'button1'}}>Button 1</button>
<button {{action 'action' 'button2'}}>Button 2</button>

```

---

<div class="post-metadata">

**Author:** ![ef4](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/ef4/32/13470_2.png) [@ef4](https://discuss.emberjs.com/u/ef4)\
**Post date:** [April 23, 2018, 7:49pm UTC](https://discuss.emberjs.com/t/passing-parameter/14608/4 "2018-04-23T19:49:22Z")

</div>

The value of passing parameters to actions like in @alexspeller’s second example is even clearer if you consider a big loop:

```auto
{{#each tweets as |tweet|}}
  <div>{{tweet.text}}</div>
  <button {{action 'fav' tweet}}>Fav</button> 
{{/each}}

```

```auto
export default Component.extend({
  actions: {
    fav(tweet) {
      alert(`You faved a tweet that says ${tweet.text}`);
    }
  }
})

```
