0
votes

I have followed the ember guide to create an handlebar helper like in this jsbin

This is the helper

Ember.Handlebars.registerBoundHelper('format-date', function(format, date) {
  return moment(date).format(format);
});

I can successfully reuse in my jsbin but i get an error when i apply the same helper in my application, this is the error Uncaught TypeError: fn.apply is not a function in my helper function , i am not implementing it correctly in my ember-cli

This is the same helper in my application

import Ember from 'ember';

export default Ember.Handlebars.registerBoundHelper('format-date', function(format, date) {
        return moment(date).format(format);
});

What's the problem?

I have also used makeBoundHelper instead of registerBoundHelper

Just to let you know i have generated the ember helper in these steps

1) From command prompt run ember generate helper "format-date"

This was the helper generated

import Ember from 'ember';

export function formatDate(params/*, hash*/) {
  return params;
}

I am definitely mistaking the way i am exporting the format-date helper

How it should be in my ember-cli?

P.s. I am still using Ember 1.12.0 , i have seen a similar issue here

1
it is definitely due to ember version that you are using, api have changed of making helpers, current 2.x api is most simplest Ember.Helper.helper(your helper code) if possible upgrade your emberBek

1 Answers

0
votes

I had to update to Ember Version 1.13.7 and change the helper to this:

import Ember from 'ember';

export function formatDate(params) {
  var date = params[0];
  return moment(date).format('LLL');
}

export default Ember.Helper.helper(formatDate);