0

Given a controller like:

App.SignInController = Ember.Controller.extend
  authenticated: false
  authenticatedDidChange: (() =>
    console.log @get('authenticated')
  ).observes('controller.authenticated')

This doesn't seem to work so I must not understand how observers works. I think it is supposed to created an observer on controller.authenticated. However when I call @set("authenticated", true) nothing is logged.

Updated: I did try replacing controller.authenticated with App.signInController.authenticated to no avail.

What am I missing?

rmontgomery429
  • 14,660
  • 17
  • 61
  • 66
  • The better solution is to use what @ryan suggests. Though, relying on `App.signInController.authenticated` could work, if you are sure that the object App.signInController has been instanciated. – sly7_7 Oct 27 '12 at 23:35

1 Answers1

1

Eventually I stumbled upon an answer this Yehuda Katz on Quora.

App.friendsController = Ember.ArrayProxy.extend({
  contentDidChange: function() {
    // stuff here
  }.observes('content')
});

After reviewing this answer I noticed that the observes call only specifies the name of the property with no controller or App.signInController prefix. Changing my solution above to just observes('authenticated') works.

App.SignInController = Ember.Controller.extend
  authenticated: false
  authenticatedDidChange: (() ->
    console.log @get('authenticated')
  ).observes('authenticated')
rmontgomery429
  • 14,660
  • 17
  • 61
  • 66
  • Perfectly right, like computed properties, observers 'path' must be either relative to the current object, or absolute from a global namespace. – sly7_7 Oct 27 '12 at 23:23