Note that there are some explanatory texts on larger screens.

plurals
  1. POEmber.js Action error: "Nothing handled the event"
    text
    copied!<p>I'm working on my first Ember.js app, and though I have a template loading, when I attempt to invoke an action that I've defined in the controller, I'm getting an error: "Uncaught Error: Nothing handled the event 'showNew'." I'm not sure if I've set up the route and controller incorrectly, or if I'm missing something else.</p> <p>./router.js:</p> <pre><code>Seanchai.Router.map(function(){ this.resource("stories", function(){ this.route('new'); }); }); Seanchai.StoriesRoute = Ember.Route.extend({ model: function(){ Seanchai.Story.find(); } }); Seanchai.Router.reopen({ location: 'history' }); </code></pre> <p>./controllers/stories_controller.js:</p> <pre><code>Seanchai.StoriesController = Ember.ArrayController.extend({ showNew: function() { this.set('isNewVisible', true); } }); </code></pre> <p>./templates/stories/index.hbs:</p> <pre><code>&lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;ID&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; {{#each stories}} {{view Seanchai.ShowStoryView storyBinding="this"}} {{/each}} {{#if isNewVisible}} &lt;tr&gt; &lt;td&gt;*&lt;/td&gt; &lt;td&gt; Test &lt;/td&gt; &lt;/tr&gt; {{/if}} &lt;/tbody&gt; &lt;/table&gt; &lt;div class="commands"&gt; &lt;a href="#" {{action showNew}}&gt;New Story&lt;/a&gt; &lt;/div&gt; </code></pre> <p>If I move the action into a router, like so, it works, but based on the documentation it looks like I should be able to do this in the controller.</p> <p>updated ./router.js:</p> <pre><code>Seanchai.Router.map(function(){ this.resource("stories", function(){ this.route('new'); }); }); Seanchai.StoriesRoute = Ember.Route.extend({ model: function(){ Seanchai.Story.find(); }, events: { showNew: function() { this.set('isNewVisible', true); } } }); Seanchai.Router.reopen({ location: 'history' }); </code></pre> <p>I'm obviously missing something, but I'm not sure what.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload