What is the right way to extend a main controller within a meteor package?
This is my case, the main controller is inside the app.js
file, located in
both/controllers/app.js
The content is
AppController = RouteController.extend({
layoutTemplate: 'appLayout'
});
Inside my-package folder, I've created a router.js
file
packages/my-package/lib/router.js
Below the content of the file, here came the question: why if I move the DashboardController
declaration outside the Meteor.startup() function, it doesn't work?
DashboardController = AppController.extend({}); // here doesn't work
Meteor.startup(function () {
Router.route('/dashboard', {
controller: DashboardController,
name: 'dashboard'
});
The output is
ReferenceError: AppController is not defined
why if I move the DashboardController declaration outside the Meteor.startup() function, it doesn't work?
That's because of the load order of Meteor build process : every package JS files are loaded according to dependencies between them and only after the actual application code is executed (which makes sense).
The solution is to move your DashboardController
inside a Meteor.startup
block so that it's executed after the application code had a chance to define AppController
.
You could also move your AppController
inside an application-core
or application-controllers
local package of yours and depend on that package.