Описание тега angularjs-service
Service
Gives us the instance of a function (object) you just instantiated with the
new
keyword and you’ll add properties tothis
and the service will returnthis
. When you pass the service into your controller, those properties onthis
will now be available on that controller through your service (hypothetical scenario).Singleton and will only be created once
Usage: if you're using a class you could use the service provider
Syntax:
module.service('serviceName', *func reference or anonymous*);
Services are a feature that Angular brings to client-side web apps from the server side, where services have been commonly used for a long time. Services in Angular apps are substitutable objects that are wired together using dependency injection (DI).
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
).
You can also create your own custom services.
Services are also used for communication between application components through DI, and can be accessed from controllers, directives, filters and other services.
AngularJS.service
module.service('MyService', function() {
this.method1 = function() {
//...
}
this.method2 = function() {
//...
}
});