2

Consider the below snippet in Handlebar written for Ember.js:

<script type="text/x-handlebars" id="courses/selectedCourse">
    <div id="selectedCourse">

    {{#if IsRegistered}}
        <div class="XX">
            Registered for the course
        </div>
        {{else}}
            <div class="YY">
                <button {{action registerForCourse}}>Register</button>
            </div>
     {{/if}}

        <h1>{{courseTitle}}</h1>            
        <div class="selectedCourseItem">            
            <img id="selectedCourse" {{bindAttr src="imageUrl"}}/>
        </div>

    </div>
</script>

Issue1 : Content is not getting refreshed immediately after Registering for a course.

Issue2 : On changing the selected courses couple of times, the content is displayed twice and overlapping.

Following is the message I see in FireBug:

TypeError: node is undefined

[Break On This Error]

node.unchain(key, path);

If I remove the #if statement, everything works well.

What am I doing wrong?

Community
  • 1
  • 1
neo
  • 425
  • 3
  • 11

2 Answers2

3

I had a similar issue and fixed it by making the first letter of the argument in the if statement lower case

{{#if isRegistered}}
scotta7exander
  • 383
  • 4
  • 11
  • Remarkably, I had the same issue with a first-char uppercase variable. Making the first letter lowercase fixed the issue. Madness! – JamesG Mar 21 '14 at 17:32
0

Ember is making an assumption based on convention that the capitalized property name indicates global scope. You have the option of modifying your variable name to be lowercase, or qualifying the reference. If the property is on your model, for example, you can use

{{#if model.isRegistered}}

to avoid this error.

rdavisau
  • 895
  • 6
  • 12