Reputation: 44501
I have this jsbin. My problem is that I am trying to trigger an action
:
<a {{action controllers.nodesIndex.destroyAllRecords this}}><i class="icon-remove-circle"></i><a/>
But I get an:
Uncaught Error: Nothing handled the event 'controllers.nodesIndex.destroyAllRecords'
(You can trigger that by pressing the little icon icon-remove-circle
on the top-right, and checking the error on the js console)
But my controller is properly set-up:
App.NodesIndexController = Ember.ArrayController.extend({
destroyAllRecords: function () {
console.log('destroyAllRecords called');
},
});
What am I missing here?
Upvotes: 1
Views: 340
Reputation: 1463
Since the controller for the nodes/index
template is the App.NodesIndexController
, You need to mention it as controllers.nodesIndex.destroyAllRecords
, the default target will be App.NodesIndexController
, and so you can just say <a {{action destroyAllRecords}}>
as @Thomas told.
Also for getting the length of records, just say {{this.length}}
instead of {{controllers.nodesIndex.length}}
.
I've updated your jsbin,
You'll need to say as 'controllers.controllername.methodname'
only if you are referring to some other controller than the controller for the template, and you've to give the controller's name in the needs list,
say, if you want to call a method of your 'profile' route from your 'nodes/index' template,
then
App.NodesIndexController = Ember.ArrayController.extend({
needs: ['profile'],
});
and in your template,
<a {{action controllers.profile.methodname}}>
Hope it helps.
UPDATE: Refer the solution and the bin in the comment
Upvotes: 2