Call one controller from another without reloading it

让人想犯罪 __ 提交于 2019-12-13 06:14:12

问题


I need to call one controller from another.

export default Ember.Controller.extend({
  needs   : ['another'],
  ....
  callAnother: function() {
    this.get('controllers.another').reloadIt();
  }
})

Another controller:

export default Ember.Controller.extend({
  init: function() {
     calling API
  },
  reloadIt: function() {
    calling API
  }
})

When I call this.get('controllers.another').reloadIt(). It calls init and reloadIt.

Is it possible to call it without init because it's already loaded.

Thanks.


回答1:


Please try using macros for this purpose is a lot easier.

export default Ember.Controller.extend({
  needs   : ['another'],

 callAnother: Ember.computed.alias('controllers.another.reloadIt'),

 actions:{

    callController: function(){
       this.get('callAnother');
     },

  }
})


来源:https://stackoverflow.com/questions/38085510/call-one-controller-from-another-without-reloading-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!