3
votes

I am using starter kit from Emebr JS and added a simple anchor tag with {{action hello}} to application template.

I am pre-compiling the template with handlebars pre-compiler. When I tried to run this, it is throwing an error.

UnCaught Error: Could not find property 'action'

Previously I used to do the same thing with ember-1.0.pre.js, which was working fine. But When I included the new library of ember (ember-1.0.0-pre.2.js), it is throwing up this error.

In both the cases, I am using handlebars-1.0.rc.1.min.js.

Can anyone please help me out in fixing the issue. Detailed information of what handlebars and libraries I am using are listed below.

Template compiled with handlebars pre-compiler. application.handlebars

<h1>Hello from Ember.js</h1> 
<a {{action hello}}>Say Hello!</a>

My HTML Page:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  <script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.2.min.js"><\/script>')</script>
  <script src="js/libs/handlebars-1.0.0.beta.6.js"></script>
  <script src="js/libs/ember-1.0.0-pre.2.min.js"></script>

  <script src="handlebars/compiled/views.handlebars.js"></script>

  <script src="js/app.js"></script>

views.handlebars.js contains the compiled handlebar.

App.js:

var App = Ember.Application.create();

App.ApplicationController = Ember.Controller.extend();
App.ApplicationView = Ember.View.extend({
  templateName: 'application'
});

App.Router = Ember.Router.extend({
  root: Ember.Route.extend({
    index: Ember.Route.extend({
      route: '/'
    }),
    hello: function() {
        console.log("Hello and Welcome");
    }
  })
})

App.initialize();
2
Have you tried to place the views.handlebars.js before your libs? I think Handlebar templates always have be in front of the Ember libraries. Maybe you have a fiddle available?mavilein
That's likely the issue hereMilkyWayJoe
I just tried placing views.handlebars.js before libraries. But it is throwing the same error.user1374656

2 Answers

5
votes

When precompiling handlebars views for ember you need to use Ember.Handlebars, not Handlebars. I suspect that may be the problem.

More discussion here: Emberjs Handlebars precompiling

1
votes

Thanks for the link, but I started to use ember-precompile instead of handlebars pre-compilation. You can find the ember-precompile at https://github.com/gabrielgrant/node-ember-precompile

This module uses older libraries of handlebars and ember, before running this one has to upgrade the libraries to latest versions and then run it. Path to libraries can be modified in "index.js". Adding latest libraries and modifying "index.js" has worked for me.