1

I'm invoking an Ember action via a link:

<a {{action "openApps"}}>Apps</a>

and handling it in the appropriate controller

actions: {
  openApps: function() {
    //...
  }
}

How do I get a reference to the <a> which invoked the action inside the controller-function.

Hedge
  • 16,142
  • 42
  • 141
  • 246
  • 2
    There may be a better way, but you could define a `click` action in your view/component, which will be passed an event, then do `this.send('openApps', event.target)` from that click handler, then write `openApps: function(target)`. –  Mar 19 '15 at 09:07
  • This is not a component and I'm not using Views anymore since they are going to be deprecated – Hedge Mar 19 '15 at 09:23
  • 1
    I think you're going to need a component for this. (For a similar question now a bit out of date, see http://stackoverflow.com/questions/18833951/get-action-target-element-in-ember.) By the way, what are you planning on doing with the `` element once you have it? –  Mar 19 '15 at 10:43

1 Answers1

0

It's funny. Someone answered the question yesterday with exactly what I wanted but he/she deleted the answer. Therefore here it is:

It is perfectly possible to get the target of an action by using window.event.target:

actions: {
  openNav: function() {
    Ember.$(window.event.target).slideToggle();
  }
}
Hedge
  • 16,142
  • 42
  • 141
  • 246