I have the following props in my Controller
App.TeamController = Ember.ObjectController.extend(
involvedProjectTeams: (->
return @get("content.projectTeams").filter (projectTeam, index, enumerable) ->
projectTeam.get("sdeScopingWeeks") isnt 0
).property("[email protected]")
notInvolvedProjectTeams: (->
return @get("content.projectTeams").filter (projectTeam, index, enumerable) ->
return projectTeam.get("sdeScopingWeeks") is 0
).observes("[email protected]")
)
I then iterate over both involvedProjectTeams as well as notInvolvedProjectTeams in the underlying template. I am getting the following error:
Uncaught TypeError: Object function () {
return this.get("content.projectTeams").filter(function(projectTeam, index, enumerable) {
return projectTeam.get("sdeScopingWeeks") === 0;
});
} has no method 'addArrayObserver'
Why does property() work as expected but observes throws an error?
Thanks!!
Ember supports observing any property, including computed properties. You can set up an observer on an object by using the observes method on a function: Because the fullName computed property depends on firstName , updating firstName will fire observers on fullName as well. Observers in Ember are currently synchronous.
You can define inline observers by using the Ember.observer method if you are using Ember without prototype extensions: You can also add observers to an object outside of a class definition using addObserver:
Observers in Ember are currently synchronous. This means that they will fire as soon as one of the properties they observe changes. Because of this, it is easy to introduce bugs where properties are not yet synchronized: This synchronous behaviour can also lead to observers being fired multiple times when observing multiple properties:
Old Guides - You are viewing the guides for Ember v1.10.0 . VIEW v3.28.0 Ember supports observing any property, including computed properties. You can set up an observer on an object by using the observes method on a function: Because the fullName computed property depends on firstName , updating firstName will fire observers on fullName as well.
From Ember's guides
In a nutshell, computed properties let you declare functions as properties. You create one by defining a computed property as a function, which Ember will automatically call when you ask for the property. You can then use it the same way you would any normal, static property.
So if you want to access something in the template, it should be a property.
Observers will just return the function only, so that can't be accessed in the templates. This is the reason why you get an error while accessing notInvolvedProjectTeams
, which is just a function not a property.
Define this also as a computed property, so that you can access them in the templates.
P.S: You can use, ember's reduceComputed to define these properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With