Sea guy
Sea guy

Reputation: 178

get one controller from another controller with emberjs

I'd like to get the controller from another controller.

App define

var App = Ember.Application.create();
App.Router.map(function() {
    this.route("index", {path: "/"});                                                    
    this.resource('markets', {path: "/markets"}, function() {
      this.route("sources");
    });
});

define route

App.IndexRoute = Ember.Route.extend({
    redirect: function() {
        this.transitionTo('markets');
    }
});

App.MarketsRoute = Ember.Route.extend({
    model: function () {
        return App.Markets.find();
    }
});

App.MarketsRoute = Ember.Route.extend({
    model: function () {
        return App.Markets.find();
    }
});

App.MarketsSourcesRoute = Ember.Route.extend({
    model: function(){
        return App.Sources.find();
    },
    serialize: function(model) {
        return { markets_id: model.id };
    }
});

controller define

App.MarketsSourcesController = Ember.ObjectController.extend({
    need: ['nav'],
    testmethod: function(){
       this.get("content").clear();
    }
});

App.MarketsController = Ember.ObjectController.extend({
    test:function(){
        //****************************************//
          MAIN AREA
        //****************************************//
    }
});

I am going to call testmethod() of App.MarketsController in test() of App.MarketsController.
For it, I have used this.controllerFor() and this.get()
But those dosent work. I'd like to of it.

Upvotes: 1

Views: 95

Answers (1)

selvagsz
selvagsz

Reputation: 3872

Use 'needs' to use one controller inside another controller.

App.MarketsController = Ember.ObjectController.extend({
needs: ['marketsSources'],
test:function(){
  this.get('controllers.marketsSources').testmethod();
}
});

Upvotes: 2

Related Questions