lundi 18 janvier 2016

Actions on routes / controllers

I am using:

DEBUG: -------------------------------
DEBUG: Ember             : 2.2.0
DEBUG: Ember Data        : 2.2.1
DEBUG: jQuery            : 1.11.3
DEBUG: Ember Simple Auth : 1.0.0
DEBUG: -------------------------------

I need to setup a controller when handling an action. I define an action in my application route:

// routes/application.js

import Ember from 'ember';

export default Ember.Route.extend({
    filterCategories: Ember.inject.controller('filter-categories'),

    actions: {
        openSubcategory(categoryId, subcategoryId) {
            ...
        }
    }
});

But I get:

Uncaught Error: Assertion Failed: Defining an injected controller property on a non-controller is not allowed.

This is documented nowhere (at least I can not find it), but it's ok. I will move the action to the application controller:

// controllers/application.js

import Ember from 'ember';

export default Ember.Controller.extend({
    filterCategories: Ember.inject.controller('filter-categories'),

    actions: {
        openSubcategory(categoryId, subcategoryId) {
            ...
            return false;
        },
    },

});

Now I get:

Uncaught Error: Nothing handled the action 'openSubcategory'. 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.

I am obviously handling the action in the application controller, so that's not true. I am also returning false from that action handler, so no bubbling. What could be going on? There is little documentation about actions, and it's only component related. What about actions in controllers and routes?




Aucun commentaire:

Enregistrer un commentaire