How to dynamically add elements (buttons, input elements) to a page in EmberJS?


#1

This is in JavaScript:

button = document.createElement(“BUTTON”); buttonText = document.createTextNode(“Edit”); button.setAttribute(“name”,name); button.appendChild(buttonText);


#2

Ember takes care of building up elements like that for you, based off what your templates say.

Your example code would just look like:

<button name={{name}}>Edit</button>

in a template. If you want the button to only be present sometimes, you can use a conditional:

{{#if shouldShowButton}}
  <button name={{name}}>Edit</button>
{{/if}}