ruz
ruz

Reputation: 492

Ember.js: access the current component from helper

Looking for any solution (even dirty hacks) to access the current component from a custom helper.

import Ember from 'ember';

export default Ember.Helper.extend({
  compute() {
    ... who is computing me? ...
  }
});

Upvotes: 0

Views: 185

Answers (1)

Joe Hany
Joe Hany

Reputation: 1015

Simply pass this to the helper.

Say the code example you mentioned is for format-currency helper, so you can pass the context like {{format-currency value this}}

And in the helper you can access it like:

import Ember from 'ember';

export default Ember.Helper.extend({
  compute([value, container]) {
    //... who is computing me? ...
    // container is computing you
  }
});

Upvotes: 2

Related Questions