Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this Ember.js app fail in Firefox?

Tags:

ember.js

I have a very simple Ember.js app which works correctly in IE and Chrome, but fails in Firefox (9.0.1 and 10.0). Any reason why? Here's the code:

<!doctype html>

<html>
<head>
    <title>Template Name</title>
</head>
<body>
    <script type="text/x-handlebars" data-template-name="my-template">
        {{App.user.name}}
    </script>

    <div id="container"></div>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://cloud.github.com/downloads/emberjs/ember.js/ember-0.9.4.js"></script>

    <script type="text/javascript">
        window.App = Ember.Application.create();

        App.user = Ember.Object.create({
            name: 'John'
        });

        App.view = Ember.View.create({
            templateName: 'my-template'
        });

        App.view.appendTo('#container');
    </script>
</body>
</html>
like image 255
Naresh Avatar asked Feb 10 '12 04:02

Naresh


2 Answers

The error in firefox is

uncaught exception: Error: <Ember.View:ember143> - Unable to find template "my-template".

This would seem to indicate that the template script has not been evaluated at the point where the app executes. The solution is to wait for onload. Wrap your appendTo like this:

$(function() {
    App.view.appendTo('#container');
});
like image 138
Martin Algesten Avatar answered Nov 16 '22 19:11

Martin Algesten


I just experienced the exact same issue. I found out that it was caused due to Ember being dependent on Handlebars. It looks like after version 1.0 they removed the inclusion of the Handlebars source code. After adding in the Handlebars library, the error goes away.

like image 1
Ken Hannel Avatar answered Nov 16 '22 17:11

Ken Hannel