aboutsummaryrefslogtreecommitdiffstats
path: root/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc
diff options
context:
space:
mode:
authorBrian Ford2014-03-03 12:30:33 -0800
committerBrian Ford2014-03-03 12:30:33 -0800
commit220e7bf2d448fd80d98d5c2f3cfac3902433df8f (patch)
tree9b46c834e26a813705a6c39a418f7cef51f6e45b /docs/content/guide/dev_guide.services.managing_dependencies.ngdoc
parent8d6eed21d219e459331a9f08fd46f8c67a9553da (diff)
downloadangular.js-220e7bf2d448fd80d98d5c2f3cfac3902433df8f.tar.bz2
docs(guide/services): rewrite services documentation
Diffstat (limited to 'docs/content/guide/dev_guide.services.managing_dependencies.ngdoc')
-rw-r--r--docs/content/guide/dev_guide.services.managing_dependencies.ngdoc113
1 files changed, 0 insertions, 113 deletions
diff --git a/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc b/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc
deleted file mode 100644
index e9d8be8c..00000000
--- a/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc
+++ /dev/null
@@ -1,113 +0,0 @@
-@ngdoc overview
-@name Angular Services: Managing Service Dependencies
-@description
-
-Angular allows services to declare other services as dependencies needed for construction of their
-instances.
-
-To declare dependencies, you specify them in the factory function signature and annotate the
-function with the inject annotations either using by setting the `$inject` property, as an array of
-string identifiers or using the array notation. Optionally the `$inject` property declaration can be
-dropped (see "Inferring `$inject`" but note that that is currently an experimental feature).
-
-Using the array notation:
-
-```js
-function myModuleCfgFn($provide) {
- $provide.factory('myService', ['dep1', 'dep2', function(dep1, dep2) {}]);
-}
-```
-
-
-Using the $inject property:
-
-```js
-function myModuleCfgFn($provide) {
- var myServiceFactory = function(dep1, dep2) {};
- myServiceFactory.$inject = ['dep1', 'dep2'];
- $provide.factory('myService', myServiceFactory);
-}
-```
-
-
-Using DI inference (incompatible with minifiers):
-
-```js
-function myModuleCfgFn($provide) {
- $provide.factory('myService', function(dep1, dep2) {});
-}
-```
-
-
-Here is an example of two services, one of which depends on the other and both
-of which depend on other services that are provided by the Angular framework:
-
-```js
-/**
- * batchLog service allows for messages to be queued in memory and flushed
- * to the console.log every 50 seconds.
- *
- * @param {*} message Message to be logged.
- */
- function batchLogModule($provide){
- $provide.factory('batchLog', ['$interval', '$log', function($interval, $log) {
- var messageQueue = [];
-
- function log() {
- if (messageQueue.length) {
- $log.log('batchLog messages: ', messageQueue);
- messageQueue = [];
- }
- }
-
- // start periodic checking
- $interval(log, 50000);
-
- return function(message) {
- messageQueue.push(message);
- }
- }]);
-
- /**
- * routeTemplateMonitor monitors each $route change and logs the current
- * template via the batchLog service.
- */
- $provide.factory('routeTemplateMonitor',
- ['$route', 'batchLog', '$rootScope',
- function($route, batchLog, $rootScope) {
- $rootScope.$on('$routeChangeSuccess', function() {
- batchLog($route.current ? $route.current.template : null);
- });
- }]);
- }
-
- // get the main service to kick off the application
- angular.injector([batchLogModule]).get('routeTemplateMonitor');
-```
-
-Things to notice in this example:
-
-* The `batchLog` service depends on the built-in {@link ng.$interval $interval} and
-{@link ng.$log $log} services, and allows messages to be logged into the
-`console.log` in batches.
-* The `routeTemplateMonitor` service depends on the built-in {@link ngRoute.$route
-$route} service as well as our custom `batchLog` service.
-* Both of our services use the factory function signature and array notation for inject annotations
-to declare their dependencies. It is important that the order of the string identifiers in the array
-is the same as the order of argument names in the signature of the factory function. Unless the
-dependencies are inferred from the function signature, it is this array with IDs and their order
-that the injector uses to determine which services and in which order to inject.
-
-
-## Related Topics
-
-* {@link dev_guide.services.understanding_services Understanding Angular Services}
-* {@link dev_guide.services.creating_services Creating Angular Services}
-* {@link dev_guide.services.injecting_controllers Injecting Services Into Controllers }
-* {@link dev_guide.services.testing_services Testing Angular Services}
-
-
-## Related API
-
-* {@link ./ng Angular Service API}
-* {@link angular.injector Angular Injector API}