samedi 25 avril 2015

EmberJS: Using helpers in component properties

I'm trying to sweeten this component template:

{{#link-to 'invoice' model.next.id }}
  {{format-number model.next.amount format="USD"}} due {{format-relative model.next.due units="day"}}
{{/link-to}}

As you can see, the verbosity makes it hard to see the final link text. The following is easier to parse:

{{#link-to 'invoice' model.next.id }}
  {{amount}} due {{date}}
{{/link-to}}

To enable this syntax I'm thinking computed properties will help, but I'm unsure how to leverage the format-number and format-relative helpers from within my component definition.

So, how do I add sugar to my component so this {{format-number model.next.amount format="USD"}} becomes this {{amount}}? Am I on the right track?




Aucun commentaire:

Enregistrer un commentaire