4

As I understood there is no classical registration of module, where we can inject our dependencies like:

var myModule = angular.module('myModule', [otherModule]);

However there are file module-name.client.module.js at the root of the directorys

'use strict';
// Use Applicaion configuration module to register a new module
ApplicationConfiguration.registerModule('module-name');

Can I inject here my module like *.registerModule('module-name', [someModule]); or I should do it in angular.module('articles').config(...)?

But in config I can inject only providers, without factories

khex
  • 2,778
  • 6
  • 32
  • 56

1 Answers1

1

As far as i used angular, the best practice to load custom module and external library is to combine angularjs with requirejs.

It's done in 3 step.

First, load in your main html file a js file which builds the foundation of your system (require.config): Here you have all the parameters allowed : https://github.com/jrburke/r.js/blob/master/build/example.build.js

Example : In your html file :

<script src="path/to/require.js" data-main="path/to/yourBuildFile"></script>

In yourBuildFile file :

require.config({
    // you can define suitable names for all your external js library
    paths:{
        // don't put a ".js" at the end of the file
        'angular' : 'path/angular',
        'underscore' : 'path/underscore-min',
        '...': '...',
    },
    // and other useful things
});

Second, in the same file or in another (see the parameter deps in link above), bootstrap your app: Like explained here : https://docs.angularjs.org/guide/bootstrap

Example:

// AMD module injection, more info here : http://requirejs.org/docs/whyamd.html
define([ // inject all the external library you need + the definition of your app
    'angular',
    'require',
    'yourpath/yourApp' // don't bother here, it's explained in third point
], function(angular){
    // link your app to the document file programatically
    angular.bootstrap(document, ['nameOfYourApp']); 
});

Third, you define your app (in the "yourpath/yourApp")

Example:

define([
    'angular',
    // put all path to your directives + controllers + services
], function(angular){ // only specify parameters the library you use in the function
    // you create your sublime app :)
    angular.module('nameOfYourApp', [
        // put all the name of your modules injected above
    ]);
});

The example above is made for single page application. You can find other examples for multipage application here http://requirejs.org/docs/start.html

Aliz
  • 736
  • 1
  • 11
  • 25