I have successfully created and bound computed properties, but how can I get at them manually in other parts of my code?
App.Test = Ember.Object.extend(
value: "1"
unit: "INCH"
display: (->
value = this.get('value')
unit = this.get('unit')
return "#{value} #{unit}"
).property('value', 'unit')
)
How do I call the ‘display’ method in, say, a controller? The following shows what I thought would work…
myTest = App.Test.create()
displayValue1 = myTest.get('display')
displayValue2 = myTest.display()
displayValue1 just returns me an object, not a string. displayValue2 throws a ‘no function found” error. So how do I access this property other than a binding?
Consider computed properties as properties, not method. Even if they contains a little bit of logic, they really are properties, so you should never call them as a method.
You can access them using the classic
Ember.getmethod, as you can see below:You can try this code in this JSFiddle.