Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix the deprecated Ember.Handlebars.registerBoundHelper in Ember 1.13.9?

I am currently upgrading from Ember 1.8.1 to Ember 1.13.9. My App is sort of oldschool by NOT using the ember-cli (no es6 whatever syntax).

How do i replace the deprecated Ember.Handlebars.registerBoundHelper properly:

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

will advice you to

DEPRECATION: `Ember.Handlebars.registerBoundHelper` is deprecated. 
Please refactor to use `Ember.Helpers.helper`. 
[deprecation id: ember-htmlbars.register-bound-helper]

So i thought replacing ´Ember.Handlebars.registerBoundHelper´ with ´Ember.Helper.helper´ would do, but then these helpers are not available any more: "Uncaught Error: Assertion Failed: A helper named 'date-ago' could not be found!".

How do I register a htmlbars helper in Ember 2.0 without ES6 syntax or ember-cli magic?

like image 604
justastefan Avatar asked Mar 15 '23 21:03

justastefan


1 Answers

Just assign it to Application:

App.FormatCurrencyHelper = Ember.Helper.helper(function(params, hash) {
  var cents = params[0];
  var currency = hash.currency;
  return currency + cents * 0.01;
});

//template
{{format-currency 75 currency="$"}}

jsbin here

like image 146
artych Avatar answered Apr 28 '23 14:04

artych