Search code examples
ember.jsember-cli

Can't sendAction from event handler triggered by component


I've got a component sending an action:

this.sendAction('action', data.files)

In the template I used the component like this

{{file-upload url="api/v1/upload" action="finishedUpload"}}

In the controller handling the event I'd like to send another action (to the same controller but I get the infamous TypeError: undefined is not a function

finishedUpload: function(files) {
  this.sendAction('insertImage')
}

How can I get the context of the current controller so I can send actions in the event-handler?


Solution

  • Under controller you don't have to use sendAction, simply use send like this

    finishedUpload: function(files) {
      //action to same controller
      this.send('insertImage')
    }
    

    When in the component you have to use sendAction