Ever wanted to toggle a property from your template without creating an action? Of course you did.
I wrote a tip (#38 Pipe multiple actions) about the awesome ember-composoable-helpers add-on. Using that same add-on, here is how to toggle a boolean property without writing component/controller code.
Old way:
1 2 3 |
<button {{action 'toggleFlag' this}}> Toggle Flag </button> |
1 2 3 |
toggleFlag() { this.toggleProperty('flag'); } |
Better way:
1 2 3 |
<button {{action (toggle "flag" this)}}> Toggle Flag </button> |
That’s it – no code needed.