forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.module.html
46 lines (44 loc) · 3.37 KB
/
angular.module.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<a href="http://github.com/angular/angular.js/tree/v1.2.3/src/loader.js#L29" class="view-source btn btn-action"><i class="icon-zoom-in"> </i> View source</a><a href="http://github.com/angular/angular.js/edit/master/src/loader.js" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable="">angular.module</code>
<div><span class="hint">API in module <code ng:non-bindable="">ng</code>
</span>
</div>
</h1>
<div><h2 id="description">Description</h2>
<div class="description"><div class="angular-module-page"><p>The <code>angular.module</code> 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.</p>
<p>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 <code>module</code>) is retrieved.</p>
<h3 id="description_module">Module</h3>
<p>A module is a collection of services, directives, filters, and configuration information.
<code>angular.module</code> is used to configure the <a href="api/AUTO.$injector"><code>$injector</code></a>.</p>
<pre class="prettyprint linenums">
// Create a new module
var myModule = angular.module('myModule', []);
// register a new service
myModule.value('appName', 'MyCoolApp');
// configure existing services inside initialization blocks.
myModule.config(function($locationProvider) {
// Configure existing providers
$locationProvider.hashPrefix('!');
});
</pre>
<p>Then you can create an injector and load your modules like this:</p>
<pre class="prettyprint linenums">
var injector = angular.injector(['ng', 'MyModule'])
</pre>
<p>However it's more likely that you'll just use
<a href="api/ng.directive:ngApp"><code>ngApp</code></a> or
<a href="api/angular.bootstrap"><code>angular.bootstrap</code></a> to simplify this process for you.</p>
</div></div>
<h2 id="usage">Usage</h2>
<div class="usage"><pre class="prettyprint linenums">angular.module(name[, requires], configFn);</pre>
<h4 id="usage_parameters">Parameters</h4><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>name</td><td><a href="" class="label type-hint type-hint-object">!string</a></td><td><div class="angular-module-page"><p>The name of the module to create or retrieve.</p>
</div></td></tr><tr><td>requires <div><em>(optional)</em></div></td><td><a href="" class="label type-hint type-hint-array">Array.<string></a></td><td><div class="angular-module-page"><p>If specified then new module is being created. If
unspecified then the the module is being retrieved for further configuration.</p>
</div></td></tr><tr><td>configFn</td><td><a href="" class="label type-hint type-hint-function">Function</a></td><td><div class="angular-module-page"><p>Optional configuration function for the module. Same as
<a href="api/angular.Module#methods_config"><code>Module#config()</code></a>.</p>
</div></td></tr></tbody></table><h4 id="usage_returns">Returns</h4><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-module">module</a></td><td><div class="angular-module-page"><p>new module with the <a href="api/angular.Module"><code>angular.Module</code></a> api.</p>
</div></td></tr></table></div>
</div>