在另一个控制器Ember中调用控制器方法 [英] Calling a controllers method in another controller Ember

查看:140
本文介绍了在另一个控制器Ember中调用控制器方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ember的Ne​​ed Api调用另一个控制器中的控制器的方法。我能够得到控制器的实例,但是当我调用它的方法它会返回我这个错误 TypeError:Object [object Object]没有方法。

I am using Ember's Need Api to call a method of a controller in another controller. I am able to get the instance of the controller but when I am calling it method it returns me this error TypeError: Object [object Object] has no method.

这是我打电话的方式:

Cards.CardsIndexController = Ember.Controller.extend({
    needs: 'account_info',
     actions: {
        accountInfoStart:function(){
               console.log(this.get('controllers.account_info').test()); // error here


        }
    }
});

这是控制器的功能我想调用

This is the controller whose function I want to call

Cards.AccountInfoController = Ember.Controller.extend({


    actions:{

        test: function(){

            alert(1);
        }

    }

});

如何解决?

推荐答案

test 在技术上不是一种方法,而是一个动作或事件。使用发送方法:

test is not technically a method, but an action or event. Use the send method instead:

this.get('controllers.account_info').send('test', arg1, arg2);

这篇关于在另一个控制器Ember中调用控制器方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆