mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 15:40:22 +00:00
we now have two types of namespaces: - true namespace: angular.* - used for all global apis - virtual namespace: ng.*, ngMock.*, ... - used for all DI modules the virual namespaces have services under the second namespace level (e.g. ng.) and filters and directives prefixed with filter: and directive: respectively (e.g. ng.filter:orderBy, ng.directive:ngRepeat) this simplifies urls and makes them a lot shorter while still avoiding name collisions
36 lines
1.7 KiB
Text
36 lines
1.7 KiB
Text
@ngdoc overview
|
|
@name Developer Guide: Angular Services: Understanding Angular Services
|
|
@description
|
|
|
|
Angular services are singletons that carry out specific tasks common to web apps, such as the
|
|
{@link api/ng.$http $http service} that provides low level access to the browser's
|
|
`XMLHttpRequest` object.
|
|
|
|
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.
|
|
|
|
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 `$inject` property. For example:
|
|
|
|
myController.$inject = ['$location'];
|
|
|
|
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 `$` (such as `$http` mentioned
|
|
above). You can also create your own custom services.
|
|
|
|
|
|
## Related Topics
|
|
|
|
* {@link di About Angular Dependency Injection}
|
|
* {@link dev_guide.services.creating_services Creating Angular Services}
|
|
* {@link dev_guide.services.managing_dependencies Managing Service Dependencies}
|
|
* {@link dev_guide.services.testing_services Testing Angular Services}
|
|
|
|
## Related API
|
|
|
|
* {@link api/ng Angular Service API}
|
|
* {@link api/angular.injector Injector API}
|