Computed properties within components



I am not sure if components currently (or will) allow this.

I want to wrap a field access (from within a component template), within a computed property. The same as computed properties on controllers.

Say the field is ‘name’, and the computed property is nameOrPlaceHolder

so in the component javascript:

App.Blah-BlahComponent = Ember.Component.extend({
  nameOrPlaceHolder: function() { return this.get('name') }.property('name')

in the template:


Should this work?

I will put up a jsbin soon to illustrate more clearly…


Why not? All controllers, routes, views and other objects has computed properties. But in your case it is better to use Ember.computed.alias method:

App.Blah-BlahComponent = Ember.Component.extend({
  nameOrPlaceHolder: Ember.computed.alias('name')



It turns out I had a small typo that my tired eyes could’nt see. I tried in jsbin, it worked & I looked at it again. Voila, it works.