Diego P
Diego P

Reputation: 1758

Access application controller from didinsertelement view

I want to access application controller so I can get/set a variable (selected_date) value.

myApp.ApplicationController = Ember.Controller.extend({
    selected_date: null,
  actions: {
    }
  }
});

I would like to make edits to selected_date from a view (didinsertelement), the controller for the view is:

myApp.CreportController = Ember.ObjectController.extend({
    needs: ["application"]
});

view:

CreportController View = Ember.View.extend({
    didInsertElement: function() {
        var controller = this.get('controller');
        var selected_date = controller.get('controllers.application').get('selected_date');
        ...

Upvotes: 0

Views: 271

Answers (2)

Diego P
Diego P

Reputation: 1758

I updated the code with the solution:

var controller = this.get('controller');
var selected_date = controller.get('controllers.application').get('selected_date');

Upvotes: 0

GJK
GJK

Reputation: 37369

You have your properties wrong. Using the needs functionality puts those controllers in a controllers property. Your view can then access its own controller using the controller property. So you need to do this in your view:

didInsertElement: function() {
    var selected_date = this.get('controller.controllers.application').get('selected_date');
}

Upvotes: 2

Related Questions