What is called in the Controller after SetupController?


#1

Is there a method called in a controller after a route does a SetupController?

What are you my options?


#2

No, but you can easily do it yourself if you want.

App.FooRoute = Ember.Route.extend({
    setupController: function(controller, model) {
        this._super(controller, model);
        Ember.tryInvoke(controller, 'afterSetup');
    }
});

#3

Excellent, thanks! Works like a charm


#4

Another alternative is this

export default Em.Route.extend({})
  detectController: function() {
    console.log('hi')
  }.observes('setupController').on('init')
});

Dunno if there are any drawbacks though, maybe it breaks somewhere, but off the top of my head, I don’t think so.


#5

I don’t think that will work. The observes() function is only called when the setupController property changes. In this case, setupController isn’t changing, it’s just being called.


#6

Here’s a JSBIN -> http://emberjs.jsbin.com/fohofoqaxusu/1/edit


#7

It’s possible, but I don’t know if there’s something horribly wrong with it. Reading up on it though.


#8

That’s only working because you have the .on('init') included. Right now it’s only firing when the controller singleton is created, which means it’ll only fire the first time the controller is setup from the route.


#9

Sweet, thanks for clarifying that!


#10

Here is a JSBin I made a while back that shows the route hook order:

http://emberjs.jsbin.com/rolo/1