I wrote this very simple Ember code, but for some reason the event doesn’t seem to fire when I press the button. Any tips?
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<script type="text/x-handlebars">
{{#view CounterView}}
Counter: {{Counter.value}}
<button {{action "increment"}}>Add 1</button>
{{/view}}
</script>
<script src="jquery-1.7.2.min.js"></script>
<script src="handlebars-1.0.rc.1.min.js"></script>
<script src="ember-1.0.pre.min.js"></script>
<script>
Counter = Ember.Object.create({
value: 1,
})
CounterView = Ember.View.extend({
increment: function(event) {
Counter.incrementProperty('value');
}
})
</script>
</body>
</html>
In order to make the event system working, Ember.js needs an application to be created and initialized (the framework does it for you).
Applying your example to the default Ember.js starting jsfiddle, here is the result:
Html template:
Javascript:
Working fiddle: http://jsfiddle.net/6p6XJ/260/