forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev_guide.services.understanding_services.html
39 lines (31 loc) · 1.94 KB
/
dev_guide.services.understanding_services.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
<h1><code ng:non-bindable=""></code>
<span class="hint"></span>
</h1>
<div><p>Angular services are singletons that carry out specific tasks common to web apps, such as the
<a href="api/ng.$http"><code>$http service</code></a> that provides low level access to the browser's
<code>XMLHttpRequest</code> object.</p>
<p>To use an Angular service, you identify it as a dependency for the dependent (a controller, or
another service) that depends on the service. Angular's dependency injection subsystem takes care
of the rest. The Angular injector subsystem is in charge of service instantiation, resolution of
dependencies, and provision of dependencies to factory functions as requested.</p>
<p>Angular injects dependencies using "constructor" injection (the service is passed in via a factory
function). Because JavaScript is a dynamically typed language, Angular's dependency injection
subsystem cannot use static types to identify service dependencies. For this reason a dependent
must explicitly define its dependencies by using the <code>$inject</code> property. For example:</p>
<pre><code> myController.$inject = ['$location'];
</code></pre>
<p>The Angular web framework provides a set of services for common operations. Like other core Angular
variables and identifiers, the built-in services always start with <code>$</code> (such as <code>$http</code> mentioned
above). You can also create your own custom services.</p>
<h3>Related Topics</h3>
<ul>
<li><a href="guide/di">About Angular Dependency Injection</a></li>
<li><a href="guide/dev_guide.services.creating_services">Creating Angular Services</a></li>
<li><a href="guide/dev_guide.services.managing_dependencies">Managing Service Dependencies</a></li>
<li><a href="guide/dev_guide.services.testing_services">Testing Angular Services</a></li>
</ul>
<h3>Related API</h3>
<ul>
<li><a href="api/ng">Angular Service API</a></li>
<li><a href="api/angular.injector"><code>Injector API</code></a></li>
</ul></div>