How to include Angular modules in separate Module

Viewed 66

I'm pretty new to Angular and am looking for some help with basic concepts. At the moment I have one module that has functions and attributes that I would like to access in a separate module.

Here's the code I would like to access:

(function() {
  'use strict';

 var recentItemRepoDep = [
'repository',
recentItemRepository
];

var repoName = 'spRecentItemRepository';

angular
  .module('repository')
  .run(repoSelfRegister(repoName))
  .factory(repoName, recentItemRepoDep);

function recentItemRepository(repository) {
  var repo = repository('APIRecentItem', {
    primaryKeys: [/*'UserName',*/ 'ItemID']
  });

  return repo;
}
})();

And here's the beginning of the code I'm trying to implement the previous code in:

(function() {
'use strict';

var salesDocumentMenuCtrlDep = [
  '$scope',
  '$state',
  '$stateParams',
  'repos',
  'spTabBarViewModel',
  'spLoader',
  'spCurrentUser',
  'salesDocsVal',
  salesDocumentMenuCtrl
];

angular
  .module('salesDocumentModule')
  .controller('salesDocumentMenuCtrl', salesDocumentMenuCtrlDep);

I'm wondering if there's a way to inject one module into another one but nothing I've tried has worked so far.

2 Answers

You can inject other modules in one main module like this:

angular
  .module('mainModule', ['other', 'modules', 'goes', 'here']);

And this injected modules can have other injected sub modules, and so on.

Way to inject module or dependency :

var App = angular.module("App", ['ui.event', 'ngResource', 'ngAnimate', ...]);

or another way :

var app = angular.module('app');
app.requires.push('newDependency');
Related