最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Calling controller action from Ember 2.0 component - Stack Overflow

programmeradmin1浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 10

You 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/

发布评论

评论列表(0)

  1. 暂无评论