For the control to listen to events using the "{property} change" syntax, property must be defined on this.options before the controller's init() gets called.
One way to ensure it's in the right place before init() is to set it inside setup():
Edit: Oops -- apparently the parent's setup() is responsible for setting up the event bindings for "{property} change" callbacks, not init() as I thought above. This is mentioned at the bottom of the docs for setup().
One way to ensure it's in the right place before init() is to set it inside setup():
- can.Control.extend({
- setup: function($el, options) {
- options.stateParams = options.data.stateParams;
- options.foo = options.foo || defaultValueFromSomewhere;
- // etc. Whatever logic you need to fill in options.yourProperty
- // make sure to call the parent's setup(), or bad things will happen
- return this._super.apply(this, arguments);
- },
- // etc
- // Then, so long as stateParams and foo are observable:
- '{stateParams} change': function() { ... },
- '{foo} change': function() { ... }
- });
Edit: Oops -- apparently the parent's setup() is responsible for setting up the event bindings for "{property} change" callbacks, not init() as I thought above. This is mentioned at the bottom of the docs for setup().