Tip
Guest Tip by Robert from ShipShape
Sometimes you just need to do a quick calculation, like adding 1 to an index, and you do not want to define a computed property in your JS file just for that.
For quick and dirty arithmetic in your templates, you can use ember-math-helpers.
Just install it like any addon
1 |
ember install ember-math-helpers |
Then for a simple case like adding one to the index, you could do:
1 |
{{add index 1}} |
It also supports multiple arguments and is composable, so you can do things like:
1 |
{{mult (div (add 15 5) 2) 10}} |
ember-math-helpers supports most basic math and all the options can be found in the README at https://github.com/shipshapecode/ember-math-helpers
Credits & Links
Ship Shape
Ship Shape is a Washington D.C. based Ember consultancy. We leverage Ember.js, and all the latest technologies, to create truly ambitious applications.
Share A Tip
Email me at emad@emberdaily.tips if you have a good ember tip.
If you are enjoying my daily tips please spread the word with this one-click tweet.
If you do NOT like the tips then please reply to this email and let me know how I can improve them.