Class Helper
publicDefined in: | packages/@ember/-internals/glimmer/lib/helper.ts:40 |
---|---|
Module: | @ember/component |
Since: | v1.13.0 |
import Helper from '@ember/component/helper';
Ember Helpers are functions that can compute values, and are used in templates. For example, this code calls a helper named format-currency
:
app/templates/application.hbs
<Cost @cents={{230}} />
app/components/cost.hbs
<div>{{format-currency @cents currency="$"}}</div>
Additionally a helper can be called as a nested helper. In this example, we show the formatted currency value if the showMoney
named argument is truthy.
{{if @showMoney (format-currency @cents currency="$")}}
Helpers defined using a class must provide a compute
function. For example:
currency.js
import Helper from '@ember/component/helper'; export default class extends Helper { compute([cents], { currency }) { return `${currency}${cents * 0.01}`; } }
Each time the input to a helper changes, the compute
function will be called again.
As instances, these helpers also have access to the container and will accept injected dependencies.
Additionally, class helpers can call recompute
to force a new computation.
Methods
Properties
No documented items
Events
No documented items
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/classes/Helper