Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4828

Component attribute and a computed property in it with the same name: possible?

$
0
0

@Myrdhin wrote:

Hello,

Beginner, I write this component:

export default Ember.Component.extend({
    items : Ember.computed('items.[]', function(){
        return this.getAttr('items').map(function(item) {
            item.hide = true;
            return Ember.Object.create(item);
        });
    }),

    ...
});

In my component's template:

{{#each items as |item|}}
    <span class={{if item.hide "hide"}}>{{item.name}}</span>
{{/each}}

And in my controller's template:

{{my-component items=controllerItems}}

But, when a render my-component, 'items' do not have a 'hide' property (the computed property 'items' is not called)... If i rename my computed property to 'getItems':

export default Ember.Component.extend({
    getItems : Ember.computed('items.[]', function(){
       ...
    }),

    ...
});

and use it in my component's template like this:

{{#each getItems as |item|}}
    <span class={{if item.hide "hide"}}>{{item.name}}</span>
{{/each}}

All work...

Why can i not have a computed property with the same name as my component's attribute ? thanks,

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4828

Trending Articles