diff options
| author | Brian Ford | 2014-03-03 12:30:33 -0800 |
|---|---|---|
| committer | Brian Ford | 2014-03-03 12:30:33 -0800 |
| commit | 220e7bf2d448fd80d98d5c2f3cfac3902433df8f (patch) | |
| tree | 9b46c834e26a813705a6c39a418f7cef51f6e45b /docs/content/guide/dev_guide.services.understanding_services.ngdoc | |
| parent | 8d6eed21d219e459331a9f08fd46f8c67a9553da (diff) | |
| download | angular.js-220e7bf2d448fd80d98d5c2f3cfac3902433df8f.tar.bz2 | |
docs(guide/services): rewrite services documentation
Diffstat (limited to 'docs/content/guide/dev_guide.services.understanding_services.ngdoc')
| -rw-r--r-- | docs/content/guide/dev_guide.services.understanding_services.ngdoc | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/docs/content/guide/dev_guide.services.understanding_services.ngdoc b/docs/content/guide/dev_guide.services.understanding_services.ngdoc deleted file mode 100644 index b1750884..00000000 --- a/docs/content/guide/dev_guide.services.understanding_services.ngdoc +++ /dev/null @@ -1,60 +0,0 @@ -@ngdoc overview -@name Angular Services: Understanding Angular Services -@description - -## What are Angular Services? - -Angular services are singletons objects or functions that carry out specific tasks common to web apps. -Angular has a number of built in services, such as the {@link ng.$http $http service}, which -provides access to the browser's `XMLHttpRequest` object for making requests to a server. Like other core -Angular variables and identifiers, the built-in services always start with `$` (such as `$http` mentioned -above). You can also create your own custom services. - -## Using a Service - -To use an Angular service, you identify it as a dependency for the component (controller, service, -filter or directive) 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 components as requested. - -Angular injects dependencies using -["constructor" injection](http://misko.hevery.com/2009/02/19/constructor-injection-vs-setter-injection/). -The dependency is passed to the component's factory/constructor 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 component must, explicitly, define its dependencies by using one of the -{@link di injection annotation} methods. For example, by providing a `$inject` property: - - var MyController = function($location) { ... }; - MyController.$inject = ['$location']; - myModule.controller('MyController', MyController); - -Or by providing an "inline" injection annotation: - - var myService = function($http) { ... }; - myModule.factory('myService', ['$http', myService]); - -## Defining a Service - -Application developers are free to define their own services by registering their name, and **service -factory function**, in Angular modules. - -The purpose of the **service factory function** is to generate the single object, or function, that -represents the service to the rest of the application. That object, or function, will then be -injected into any component (controller, service, filter or directive) that specifies a dependency -on the service. - -Angular factory functions are executed lazily. That is, they are only executed when needed -to satisfy a dependency, and are then executed exactly once for each service. Everything that is -dependent on this service gets a reference to the single instance generated by the service factory. - -## Related Topics - -* {@link guide/di About Angular Dependency Injection} -* {@link guide/dev_guide.services.creating_services Creating Angular Services} -* {@link guide/dev_guide.services.managing_dependencies Managing Service Dependencies} -* {@link guide/dev_guide.services.testing_services Testing Angular Services} - -## Related API - -* {@link ./ng Angular Service API} -* {@link angular.injector Injector API} |
