I’m trying to set a computed property in a component on a property that changes in a controller.
I pass the property from controller to component like this:
{{my-posts category=category}}
but the computedProperty on the component doesn’t work:
postsFiltered: Ember.computed('category', function () {
console.log('computed postsFiltered() with category: ' + this.get('category'));
this.set('myMessage', 'This is the message!');
}),
computed properties are lazy, and do not compute until you use them… in your twiddle, you are not using the postsFiltered property, so it doesn’t get computed.
Use {{postsFiltered}} instead of using {{myMessage}} in the template. And change the postsFiltered computed property to return a value instead of setting another property…
postsFiltered: Ember.computed('category', function () {
console.log('computed postsFiltered() with category: ' + this.get('category'));
return this.get('category'); // <- return the category here (or return other computed value)
}),
then in the template:
Message on computed property "category": {{postsFiltered}}