Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bindings on ObjectController - Ember.js

When you try adding a binding to an ObjectController it doesn't work.

App.FailController = Em.ObjectController.extend({
    content: null,
    myBinding: "App.router.myController" // <-- fails
});

Error:

Uncaught Error: assertion failed: Cannot delegate set('my', ) to the 'content' property of object proxy <.FailController:ember154>: its 'content' is undefined.

It tries adding it to the content property.

jsFiddle: demo

like image 461
Ilia Choly Avatar asked Sep 19 '12 20:09

Ilia Choly


2 Answers

credits: to caligo-mentis who answered this over at github.

ObjectProxy delegates any call to set to the content property unless a property with the same name exists on the ObjectProxy instance. The simple solution is to define a property with the desired name prior to declaring the binding.

App.FailController = Em.ObjectController.extend({
    my: null,
    myBinding: "App.router.myController" // <-- works
});

jsFiddle: demo

like image 171
Ilia Choly Avatar answered Nov 14 '22 18:11

Ilia Choly


Alternative solution:

App.FailController = Em.ObjectController.extend({
    content: Ember.Object.create(),
    my: function() {
      return App.router.myController;
    }.property('App.router.myController')
});

or better:

App.FailController = Em.ObjectController.extend({
    content: Ember.Object.create(),
    my: Ember.computed.alias('App.router.myController')
});
like image 29
Panagiotis Panagi Avatar answered Nov 14 '22 19:11

Panagiotis Panagi