3

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.

1
  • To get better feedback you should know that what you are calling 'angular' is now supposed to be called 'AngularJS'. 'Angular' is suppoosed to refer to 'Angular 2/4'. Commented Sep 28, 2017 at 18:37

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.