I'm trying to add a couple of buttons to my page at run time. The buttons are created and pushed into a containerView. See the addButtons function below.
Given a controller:
RE.MenuController = Em.ArrayController.extend
addButtons: ->
console.log "addButtons"
container = Ember.ContainerView.create()
container.append()
prevButton = RE.ButtonView.create()
container.pushObject(prevButton)
and a view:
RE.ButtonView = Em.View.extend
classNames: 'menuLink'
tagName: 'button'
templateName: 'button'
click: (e) ->
alert 'button clicked'
I'm never seeing the expected alert when I click on the button. Why wouldn't the click event be firing?
The html for the button looks like:
<button id="ember420" class="ember-view menuLink">TEST</button>
There's no data-ember-action there.
Should I be using this approach or use the action helper in the template?
thanks,
Martin
Ember.View event handlers (in your case, the click function) are invoked by Ember's EventDispatcher which listens on the application root element and delegates events. The event dispatcher is only instantiated by an Ember.Application. Are you creating an Application? If not, the events will never be dispatched.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With