forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.injector.html
47 lines (43 loc) · 2.52 KB
/
angular.injector.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
47
<h1>angular.injector</h1>
<div class="angular-injector"><h2>Description</h2>
<div class="description"><p>Creates an injector function that can be used for retrieving services as well as for
dependency injection (see <a href="#!/guide/dev_guide.di">dependency injection</a>).</p>
<p>Angular creates an injector automatically for the root scope and it is available as the
<a href="#!/api/angular.scope.$service"><code>$service</code></a> property. Creation of the injector automatically creates
all of the <code>$eager</code> <a href="#!/api/angular.service"><code>services</code></a>.</p></div>
<h2>Usage</h2>
<div class="usage"><div ng:non-bindable=""><pre class="brush: js; html-script: true;">angular.injector([factoryScope][, factories][, instanceCache]);</pre>
</div>
<h3>Parameters</h3>
<ul class="parameters"><li><code ng:non-bindable="">factoryScope<i>(optional={})</i> – {Object} – </code>
<p><code>this</code> for the service factory function.</p></li>
<li><code ng:non-bindable="">factories<i>(optional=angular.service)</i> – {Object.<string, function()>} – </code>
<p>Map of service factory
functions.</p></li>
<li><code ng:non-bindable="">instanceCache<i>(optional={})</i> – {Object.<string, function()>} – </code>
<p>Place where instances of services are
saved for reuse. Can also be used to override services specified by <code>serviceFactory</code>
(useful in tests).</p></li>
</ul>
<h3>Returns</h3>
<div class="returns"><code ng:non-bindable="">{function()}</code>
– <p>Injector function:</p>
<ul>
<li><code>injector(serviceName)</code>:
<ul><li><code>serviceName</code> - <code>{string=}</code> - name of the service to retrieve.</li></ul></li>
</ul>
<p>The injector function also has these properties:</p>
<ul>
<li>an <code>invoke</code> property which can be used to invoke methods with dependency-injected arguments.
<code>injector.invoke(self, fn, curryArgs)</code>
<ul><li><code>self</code> - "<code>this</code>" to be used when invoking the function.</li>
<li><code>fn</code> - the function to be invoked. The function may have the <code>$inject</code> property which
lists the set of arguments which should be auto injected
(see <a href="#!/guide/dev_guide.di">dependency injection</a>).</li>
<li><code>curryArgs(array)</code> - optional array of arguments to pass to function invocation after the
injection arguments (also known as curry arguments or currying).</li></ul></li>
<li>an <code>eager</code> property which is used to initialize the eager services.
<code>injector.eager()</code></li>
</ul></div>
</div>
</div>