I need to trigger a controller action each time a controller is transitioned to (the 'modeller' route), but I can't seem to get it working. My router.js file is:
var Router = Ember.Router.extend({
location: config.locationType,
actions: {
loading: function() {
this.controllerFor('modeller').send('loading');
},
didTransition: function() {
this.controllerFor('modeller').send('didTransition');
}
}
});
Router.map(function() {
this.route('modeller', { path: 'modeller'});
this.route('welcome', { path: '/'});
});
export default Router;
And my modeller controller:
export default Ember.Controller.extend({
needs: 'modeller',
loading: function () {
console.log("loading")
},
didTransition: function () {
console.log("didTransition")
},
});
But I can't get any of those actions to log to the console. Any pointers greatly appreciated.
UPDATE:
Probably should have mentioned I'm using Ember 2.1.0!
So the solution I used was setupController - but I also needed to put that into a specific modeller route file under app/routes/modeller.js. Previously I was trying to do everything in the app/router.js and it didn't work there. So the final solution is:
# app/routes/modeller.js
import Ember from 'ember';
export default Ember.Route.extend({
setupController: function(controller, model) {
this.controllerFor('modeller').activate();
}
});
and ..
# app/controllers/modeller.js
export default Ember.Controller.extend({
needs: 'modeller',
activate: function () {
console.log("activate")
},
});