Now that Ember 2.0 decided to remove the Ember.View pletely 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?
Now that Ember 2.0 decided to remove the Ember.View pletely 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?
Share Improve this question asked Sep 23, 2015 at 13:35 Maksim LuzikMaksim Luzik 6,7434 gold badges44 silver badges61 bronze badges1 Answer
Reset to default 10You could use sendAction()
in ponent and assign handler to it in template.
// some-ponent.js
this.sendAction('actionName', params);
// template
{{some-ponent actionName="foobar"}}
// controller
actions: {
foobar(params) {
alert('action received');
}
}
Details: http://guides.emberjs./v2.0.0/ponents/sending-actions-from-ponents-to-your-application/