javascript - Angularjs routing controller from another module -
im building big app , , structure goes this:
each module has own folder structure controllers, directives, etc...
each folder has index.js file , other files separates each controller, each directive, etc...
the index.js file contains definition of module. instance controllers of businessmodule above:
angular.module('mycompany.businessmodule.controllers', []);
there's no dependencies here, there any.
then in firstctrl.js, can reuse module , add controller it:
angular.module('mycompany.businessmodule.controllers').controller('firstctrl', function(){ });
then app.js aggregates module want application adding them dependencies array.
angular.module('myapp', ['mycompany.businessmodule', 'mycompany.anotherbusinessmodule'],'ngroute');
now comes route include other modules view. route goes like:
var myapp = angular.module('myapp'); myapp.config(function($routeprovider) { $routeprovider // route home page .when('/', { templateurl : 'pages/home.html', controller : 'maincontroller' }) // route page .when('/about', { templateurl : 'pages/about.html', controller : 'firstctrl' }) });
now question can connect controller module specific controller have module injected in situation when myapp contains mycompany.businessmodule.controllers , has firstctrl ?
your modules file :
angular.module('myapp').config(function($routeprovider){ $routeprovider // route home page .when('/', { templateurl : 'pages/home.html', controller : 'maincontroller' }) // route page .when('/about', { templateurl : 'pages/about.html', controller : 'firstctrl' }); });
include dependency when want use it.
angular.module('app',[other deps]);
Comments
Post a Comment