Tarlen
Tarlen

Reputation: 3797

Controller not picking up on actions sent from template

I have a problem with getting my controller to respond to an action from its corresponding template

controllers/calendars/show.js

import Ember from 'ember';

export default Ember.ObjectController.extend({
  queryParams: ['year', 'week'],
  year: null,
  week: null,
  incrementWeek: function() {
    var currentWeek = this.get('week');
    var nextWeek    = moment(new Date(moment().week(currentWeek + 1))).week();

    if (currentWeek > nextWeek) {
      var currentYear = moment().year();
      this.set('year', currentYear + 1);
    }

    this.set('week', nextWeek);
  },

});

templates/calendars/show.hbs

<div class="week-control pull-left">
    <a {{action "incrementWeek"}}>Next</a>
 </div>

However, when I click the link I get an

Uncaught Error: Nothing handled the action 'incrementWeek'. If you did handle the action, this error can be caused by returning true from an action handler in a controller, causing the action to bubble.

To my knowledge, the controller doesnt return true, so Im unsure on how to proceed from here

thanks

Upvotes: 0

Views: 35

Answers (1)

Asgaroth
Asgaroth

Reputation: 4334

From the ember guides:

Routes and controllers that handle actions must place action handlers inside an actions hash. Even if a route has a method with the same name as the actions, it will not be triggered unless it is inside an actions hash.

import Ember from 'ember';

export default Ember.ObjectController.extend({
  queryParams: ['year', 'week'],
  year: null,
  week: null,

  actions: {
    incrementWeek: function() {
      // ...
    }
  }
});

Upvotes: 4

Related Questions