registerModule with dependencies

怎甘沉沦 提交于 2019-12-04 06:10:47

MEAN.js makes all the modules registered via registerModule available to all other modules in your app by adding it as a dependency to the main app called mean. Here's the part of the MEAN.js source code that does this:

var applicationModuleName = 'mean';
....
// Add a new vertical module
var registerModule = function(moduleName) {
    // Create angular module
    angular.module(moduleName, []);

    // Add the module to the AngularJS configuration file
    angular.module(applicationModuleName).requires.push(moduleName);
};

So you're on the right track, however it sounds like you are trying to inject a controller. However, in angular, controllers are not injectable. You can inject services, factories, values, and constants.

Vitaliy Khudonogov

First create your own module for example:

angular.module('app.controllers', []) - angular module with controllers.

then add controller to that module:

angular.module('app.controllers', [])
       .controller('dashboard.admin.account.controller', ['$scope', ($scope) { .... }]);

then create global module which will bind to your markup:

angular.module('app', [
  'app.controllers'
  'ui.router',
  'ngAnimate'
]);

then bootstrap your global module to markup:

domReady(function () {
  angular.bootstrap(document, ['app']);
});

Now you can use your controller.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!