Now that Ember 2.0 decided to remove the Ember.View completely I am having issues of passing actions from the view to the controller.
App.SomeView = Ember.Component.extend({
didInsertElement : function(){
var _this = this;
window.addEventListener("message",
function(event) {
_this.get("controller").send("foobar", event.data);
}, false);
}
});
App.SomeController = Ember.Controller.extend({
actions: {
foobar: function(param) {
console.log("Yey", param);
}
}
});
Because instead of Ember.View I need to use now Ember.Component. And of course then this.get("controller").send method does not work anymore. Is there some kind of workaround for this?
You could use sendAction() in component and assign handler to it in template.
// some-component.js
this.sendAction('actionName', params);
// template
{{some-component actionName="foobar"}}
// controller
actions: {
foobar(params) {
alert('action received');
}
}
Details: http://guides.emberjs.com/v2.0.0/components/sending-actions-from-components-to-your-application/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With