7

Ember の Need Api を使用して、コントローラーのメソッドを別のコントローラーで呼び出しています。コントローラーのインスタンスを取得できますが、メソッドを呼び出すと、このエラーが返されます 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


        }
    }
});

これは、関数を呼び出したいコントローラーです

Cards.AccountInfoController = Ember.Controller.extend({


    actions:{

        test: function(){

            alert(1);
        }

    }

});

どうすれば解決できますか?

4

3 に答える 3

12

test技術的にはメソッドではなく、アクションまたはイベントです。send代わりに次のメソッドを使用してください。

this.get('controllers.account_info').send('test', arg1, arg2);
于 2014-04-04T12:13:58.243 に答える
6

Emberのドキュメントによると; コンテナー内の別のコントローラーを遅延検索するプロパティを作成します。これは、別のコントローラーを定義する場合にのみ使用できます。

従来の ember アプリケーションの例:

App.PostController = Ember.Controller.extend({
  accountInfo: Ember.inject.controller()

  this.get('accountInfo').send('test')
});

最新の ember アプリケーションの例:

// in an ember app created with ember-cli
// below snippet would be the app/controllers/post.js file
import Ember from 'ember';
export default Ember.Controller.extend({
  appController: Ember.inject.controller('application')
});

Ember.inject に関するその他のドキュメントは、こちらにあります

于 2016-10-22T01:47:08.597 に答える