Search code examples
ember.jsember-app-kit

Ember App Kit Binding name resolution


What is the correct string representation of a resource to pass for property bindings in Ember app kit?

I have tried both of the following:

import Dependency from 'app/utils/utility';
export default Em.ObjectController.extend({
  sampleBinding: 'Dependency.value'
});

export default Em.ObjectController.extend({
  sampleBinding: 'utils:utility.value'
});

But the binding is not working in either case.

Any help is appreciated.

Thanks!


Solution

  • I've been researching this myself and came across a few things.

    It seems that binding in that way is somewhat deprecated in favor of using computed properties or aliases. Check out the comments on the answer for this SO question: What's the difference between Ember.computed.alias and an Ember.binding?

    Or more specifically the comments on this github issue: https://github.com/emberjs/ember.js/issues/1164#issuecomment-23200023).

    Part of the reasoning seems to be an aversion to using global/absolute paths. Also you probably don't want to bind to the class definition, but an actual instance of the class. I'm not quite sure what your utility class is, but if it were a controller the idea would be something like this:

    export default Em.ObjectController.extend({
      needs: ['utility'],
      aliasedVariable: Ember.computed.alias('controllers.utility.variableOnUtility')
    });
    

    Check out the answer for this SO question: Ember.js: data-binding between controllers

    Also this section of the ember guide: http://emberjs.com/guides/controllers/dependencies-between-controllers/