Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

if statement causes TpyeError: Cannont call unchain of undefined

im using a if statement in my handlebars template. the if statement works, but when you try change the route it causes a Uncaught TypeError: Cannot call method 'unchain' of undefined.

i have recreated the error in the following jsbin

demo : http://emberjs.jsbin.com/UnUVorUn/9

code : http://emberjs.jsbin.com/UnUVorUn/9/edit

like image 388
Billybonks Avatar asked Nov 30 '13 11:11

Billybonks


1 Answers

Your problem happens because your IsLink starts with a capital letter, there was a bug when used in a handlebars template, already fixed in 1.3.0. But if you update your ember version you will have a new problem, because ember consider a property that starts with a capital letter being a global path, so instead of sectionController.IsLink, it will lookup window.IsLink = 'teste'.

I recommend you to just update to isLink to avoid these problems:

App.SectionController = Ember.Controller.extend({
  isLink :Ember.computed.equal('model.type', 'link')
});

Template

<ul>
  {{#link-to 'index'}} index{{/link-to}}
  {{#link-to 'test'}} test{{/link-to}}
  {{#each model itemController="section"}}
    {{#if isLink}}
      <li>{{model.color}}</li>
    {{/if}}
  {{/each}}
</ul>

http://emberjs.jsbin.com/UnUVorUn/12/edit

like image 101
Marcio Junior Avatar answered Nov 16 '22 08:11

Marcio Junior