Tag Archives: angular modules

Angularjs – Modules

This blog is basically for me to look back and understand about the angularjs modules.

A module is a collection of services, directives, filters and configuration information.

The angular.module is a global place for creating, registering and retrieving angular modules. “angular.module” is the function used to retrieve or create angularjs modules. If passed two or more parameters a new module is created and if passed a single parameter it will return the module with the provided name.

   //Create a new module
   var anyModule = angular.module('anyModule', []);

   //register a new service
   anyModule.value('anyAppName', 'name');

   //configure existing services inside config method
   anyModule.config('$locationProvider', '$resourceProvider', function($locationProvider, $resourceProvider){
  //configure providers here

  //one can create an injector and load your modules too
  var injector = angular.injector(['ng', 'anyModule']);

‘angular.module’ takes 3 parameters ‘name’, ‘requires’, ‘config’.
‘name’ -> module to create or retrieve
‘requires’ -> required modules for this module to run (dependencies)
‘config’ -> any configuration for the module (Use this to register work which needs to be performed on module loading).

By default, it uses provider service to create a new instance of the service.
it uses provider service to instantiate $provider.provider(), $provider.factory(), $provider.service(), $provide.value, $provice.constant()
and registers $animation, $filterProvider, $controllerProvider, $compileProvider with the newly created module.