diff options
| author | Igor Minar | 2011-06-15 22:31:40 -0700 | 
|---|---|---|
| committer | Igor Minar | 2011-06-15 22:31:40 -0700 | 
| commit | b842642b574a2b95c53b791308ed1bf8ff9d304d (patch) | |
| tree | fb26431c5372be74de2105df77e94dea4f198489 /docs/content/guide/dev_guide.services.registering_services.ngdoc | |
| parent | d428c9910e66246c2af46602499acaeaf187d75b (diff) | |
| download | angular.js-b842642b574a2b95c53b791308ed1bf8ff9d304d.tar.bz2 | |
docs - stripping extra new lines
Diffstat (limited to 'docs/content/guide/dev_guide.services.registering_services.ngdoc')
| -rw-r--r-- | docs/content/guide/dev_guide.services.registering_services.ngdoc | 16 | 
1 files changed, 0 insertions, 16 deletions
diff --git a/docs/content/guide/dev_guide.services.registering_services.ngdoc b/docs/content/guide/dev_guide.services.registering_services.ngdoc index ea182944..cc50d678 100644 --- a/docs/content/guide/dev_guide.services.registering_services.ngdoc +++ b/docs/content/guide/dev_guide.services.registering_services.ngdoc @@ -3,12 +3,10 @@  @name Developer Guide: Angular Services: Registering Angular Services  @description -  To register a service, register a factory function that creates the service with angular's  Injector. The Injector is exposed as {@link api/angular.scope.$service scope.$service}. The  following pseudo-code shows a simple service registration: -  <pre>  angular.service('service id', function() {    var shinyNewServiceInstance; @@ -17,27 +15,21 @@ angular.service('service id', function() {  });  </pre> -  Note that you are not registering a service instance, but rather a factory function that will  create this instance when called. -  # Instantiating Angular Services -  A service can be instantiated eagerly or lazily. By default angular instantiates services lazily,  which means that a service will be created only when it is needed for instantiation of a service or  an application component that depends on it. In other words, angular won't instantiate lazy  services unless they are requested directly or indirectly by the application. -  Eager services on the other hand, are instantiated right after the injector itself is created,  which happens when the angular {@link dev_guide.bootstrap application initializes}. -  To override the default, you can request that a service is eagerly instantiated as follows: -  <pre>  angular.service('service id', function() {    var shinyNewServiceInstance; @@ -46,12 +38,10 @@ angular.service('service id', function() {  }, {$eager: true});  </pre> -  While it is tempting to declare services as eager, only in few cases it is actually useful. If you  are unsure whether to make a service eager, it likely doesn't need to be. To be more specific, a  service should be declared as eager only if it fits one of these scenarios: -  * Nothing in your application declares this service as its dependency, and this service affects the  state or configuration of the application (e.g. a service that configures `$route` or `$resource`  services) @@ -60,7 +50,6 @@ because the service passively observes the application and it is optional for ot  components to depend on it.  An example of this scenario is a service that monitors and logs  application memory usage. -  Lastly, it is important to realize that all angular services are applicaiton singletons. This means  that there is only one instance of a given service per injector. Since angular is lethally allergic  to the global state, it is possible to create multiple injectors, each with its own instance of a @@ -68,19 +57,14 @@ given service, but that is rarely needed, except in tests where this property is  important. - -  ## Related Topics -  * {@link dev_guide.services.understanding_services Understanding Angular Services}  * {@link dev_guide.services.creating_services Creating Angular Services}  * {@link dev_guide.services.managing_dependencies Managing Service Dependencies}  * {@link dev_guide.services.injecting_controllers Injecting Services Into Controllers }  * {@link dev_guide.services.testing_services Testing Angular Services} -  ## Related API -  * {@link api/angular.service Angular Service API}  | 
