Brian Gates
Brian Gates

Reputation: 514

Ember.js: Computed property involving other controller not refreshing upon load of model

I have the following code:

  App.UserController = App.EditableController.extend({
    needs: 'application',
    test: function() {
      return this.get('controller.application.me.email');
    }.property('controller.application.me.email'),
  });

  App.ApplicationController = Ember.Controller.extend({
    isPublic   : true,
    me         : null,
    init: function () {
      this.set('me', App.User.find(1));
      this._super();
    }
  });

But the computed property doesn't seem to update once the model loads (from the console):

> App.__container__.lookup('controller:Application').get('me.email')
"[email protected]"
> App.__container__.lookup('controller:User').get('test')
undefined

Am I missing something?

Upvotes: 1

Views: 1490

Answers (1)

intuitivepixel
intuitivepixel

Reputation: 23322

Assuming your App.EditableController is of type Ember.ObjectController then this should work:

App.UserController = Ember.ObjectController.extend({
  needs: 'application',
  // notice the we use here plural 'controllers' to have access to the
  // controllers defined with the 'needs' API
  contentBinding: 'controllers.application',
  test: function() {
    return this.get('content.me.email');
  }.property('content')
});

In the case that your App.EditableControlleris of type Ember.Controller than this should do the job:

App.UserController = Ember.Controller.extend({
  needs: 'application',
  // notice the we use here plural 'controllers' to have access to the
  // controllers defined with the 'needs' API
  controllerBinding: 'controllers.application',
  test: function() {
    return this.get('controller.me.email');
  }.property('controller')
});

Now doing App.__container__.lookup('controller:User').get('test') in the console should output:

"[email protected]" // or whatever your example mail is

Hope it helps.

Upvotes: 2

Related Questions