Sachin
Sachin

Reputation: 2361

How to access controller property in template?

Here,I am trying to access property of controller but it is throwing an exception Uncaught TypeError: Object [object Object] has no method 'addArrayObserver'

Template Code :

{{#each itemController="index"}}                    
    <div class="row" {{bindAttr class="item.isWithBorder:border"}}>
        {{#each item in model}}        
            {{#each item in item.home_products}}    
                {{#each item in item.contents}}    
                    <li>{{item.product_name}}</li>
                {{/each}}
            {{/each}}
        {{/each}}        
    </div>
{{/each}}

I want to show border property only for first iteration i.e. first product. Hence, one property is added in controller which i am accessing in template. Controller Code :

Astcart.IndexController = Ember.ObjectController.extend({
    init: function() {
        console.log("Item controller initialized");
        this._super();

    },      
    isWithBorder : function(){          
    return this.get("model.id") == 1;
    }.property("model.id")    

}); 

I have updated my code Here.

Upvotes: 3

Views: 2046

Answers (1)

intuitivepixel
intuitivepixel

Reputation: 23322

Here working jsfiddle: http://jsfiddle.net/fQNRk/2/

You where using the name index as your itemController index is already a reserved name so I just changed it to item now it works.

Astcart.ItemController = Ember.ObjectController.extend({
  ...

{{#each itemController="item"}}
  ...

Hope it helps.

Upvotes: 1

Related Questions