Podcast/lib/angular/docs/partials/guide/dev_guide.services.understanding_services.html
2013-08-21 19:46:51 +02:00

32 lines
2.3 KiB
HTML
Executable file

<a href="http://github.com/angular/angular.js/edit/master/docs/content/guide/dev_guide.services.understanding_services.ngdoc" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable=""></code>
<div><span class="hint"></span>
</div>
</h1>
<div><div class="developer-guide-page developer-guide-angular-services-understanding-angular-services-page"><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&#39;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&#39;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 &quot;constructor&quot; injection (the service is passed in via a factory
function). Because JavaScript is a dynamically typed language, Angular&#39;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 = [&#39;$location&#39;];</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</h2>
<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>
<h2>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></div>