Skip to content

Instantly share code, notes, and snippets.

@pablobm
Last active December 1, 2015 11:11
Show Gist options
  • Save pablobm/89c4acafe29a7ebecd4c to your computer and use it in GitHub Desktop.
Save pablobm/89c4acafe29a7ebecd4c to your computer and use it in GitHub Desktop.
Route actions don't know of Ember.Evented
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
handleMyEvent: Ember.on('myEvent', function() {
console.log('handling myEvent at the controller');
}),
});
import Ember from 'ember';
export default Ember.Route.extend({
handleMyEvent: Ember.on('myEvent', function() {
console.log('handling myEvent at the route');
}),
// actions: {
// myEvent() {
// console.log('handling myEvent explicitly at the route');
// }
// }
});
<h1>Welcome to {{appName}}</h1>
<button {{action 'myEvent'}}>send <code>myEvent</code></button>
<p>This code demonstrates that actions do not seem to behave quite like Ember.Evented events.</p>
<p>Clicking the button will trigger an action, and this goes off unhandler (see error on console). This is despite two attempts to handle it (at the controller and route) with <code>Ember.on</code>.</p>
<p>The commented out code at the route does the job when present though.</p>
<br>
<br>
{
"version": "0.4.16",
"EmberENV": {
"FEATURES": {}
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.1.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment