Chuck
Chuck

Reputation: 908

Using a handlebars helper to render a view isn't working

I am simply trying to render a view using a Handlebars helper. I keep getting a error when the app runs:

Uncaught TypeError: Cannot call method 'apply' of undefined 

Handlebars:

 <script type='text/x-handlebars'>
    {{outlet}}
  </script>

  <script type='text/x-handlebars' id="index">
    INDEX
    {{my-component-helper}}
  </script>

  <script type='text/x-handlebars' id="myComponentHelper">
  I'm here
  </script>

JS:

App = Ember.Application.create();

Ember.Handlebars.helper('my-component-helper', App.MyComponentHelperView);

App.MyComponentHelperView = Ember.View.extend({
  templateName:'myComponentHelper' 
});

Here is a JSbin illustrating the issue: http://jsbin.com/edUm/1/edit

Upvotes: 1

Views: 320

Answers (1)

mavilein
mavilein

Reputation: 11668

Your problem is the ordering. In your version App.MyComponentHelperView is undefined when the code is interpreted. Try this instead:

App = Ember.Application.create();

App.MyComponentHelperView = Ember.View.extend({
  templateName:'myComponentHelper' 
});

Ember.Handlebars.helper('my-component-helper', App.MyComponentHelperView);

Upvotes: 1

Related Questions