Elise Chant
Elise Chant

Reputation: 5196

Ember.js bubble event with the same name

I want to bubble an event with the same name from a controller to application:route and pass along parameters.

This doesn't work:

blog.hbs

<button {{action "createList"}}>Create List</button>

blog_controller.js

actions: {
  createList: function() {
    this.send('createList', 'value1', 'value2');
  }
}

application_route.js

actions: {
  createList: function(param1, param2) {
    console.log('I want to be caught here!!');
  }
}

Currently this behaviour only works if I choose different names for the actions in application_route and blog_controller such as (blogController:createIt and applicationRoute:createList), even though the bubbling order is correct.

How can I get this to work with the same method names?

Upvotes: 1

Views: 127

Answers (1)

Luke Melia
Luke Melia

Reputation: 8389

If you want to have an action continue up the handler chain without changing params, you can simply return true from the action handler.

However, in your case you want to invoke the action with a new set of params. In that case, you should send the action to the controller's target. e.g.

blog_controller.js

actions: {
  createList: function() {
    this.get('target').send('createList', 'value1', 'value2');
  }
}

Upvotes: 4

Related Questions