How to use non-element controllers that get a model from a nested route

I have a simple application that returns a model from a child route.

export default Ember.Route.extend({
    model: function(params) {
        var store = this.get("store");
        return store.find("todo", params.todo_id);
    }
});

      

When my controller is singleton (default in ember today) it works fine. The model hook for the child routes is called and the model is bound to the controller / view / template as you would expect.

The trick is that when I flip the singleton bit my model suddenly disappears / undefined from the start. Today my initializer looks like this.

import Wat from "kanban/controllers/todos/todo";

export function initialize(container, application) {
    application.register('controller:todos/todo', Wat, {singleton: true });
}

      

If you change this value from true to false, the tests are aborted / the child route never gets a model for that controller.

Is this supported in ember 1.10+, and if so, what am I doing wrong here?

Here is a github thread for more context (this is a simple sample app to show if this is or is not supported - finding an ember-cli app is minimal)

https://github.com/toranb/kanban-board-without-ember-data/tree/nonSingletonSpike

Edit

Note: When using the ember inspector, I noticed that when the singleton was right (default), I see 3 controllers after the application has rendered. But when I flip it to false I only see 2 controllers ... making me think that the option "false" is no longer supported

However, when I add a function that listens for "init" in the controller itself, I see that it gets called and the controllerFor parameter value is displayed on the stack

controller = container.lookup('controller:' + name);

      

... is called from the inner elements of ember.

export default Ember.Controller.extend({
    x: function() {
        return true;
    }.on("init")
});

      

+3


source to share





All Articles