View source Improve this doc

angular.module

API in module ng

Description

The angular.module is a global place for creating, registering and retrieving Angular modules. All modules (angular core or 3rd party) that should be available to an application must be registered using this mechanism.

When passed two or more arguments, a new module is created. If passed only one argument, an existing module (the name passed as the first argument to module) is retrieved.

Module

A module is a collection of services, directives, filters, and configuration information. angular.module is used to configure the $injector.

  1. // Create a new module
  2. var myModule = angular.module('myModule', []);
  3.  
  4. // register a new service
  5. myModule.value('appName', 'MyCoolApp');
  6.  
  7. // configure existing services inside initialization blocks.
  8. myModule.config(function($locationProvider) {
  9. // Configure existing providers
  10. $locationProvider.hashPrefix('!');
  11. });

Then you can create an injector and load your modules like this:

  1. var injector = angular.injector(['ng', 'MyModule'])

However it's more likely that you'll just use ngApp or angular.bootstrap to simplify this process for you.

Usage

  1. angular.module(name[, requires], configFn);

Parameters

ParamTypeDetails
name!string The name of the module to create or retrieve.
requires (optional) Array.<string> If specified then new module is being created. If unspecified then the the module is being retrieved for further configuration.
configFnFunction Optional configuration function for the module. Same as Module#config().

Returns

module new module with the angular.Module api.