EmberJS: Could not find property 'action'

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();

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


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.

链接地址: http://www.djcxy.com/p/73456.html

上一篇: 在Django 1.4.2中使用Ember和Handlebars

下一篇: EmberJS:无法找到属性“操作”