Описание тега angularjs-service

AngularJS services are singletons that carry out specific tasks common to web apps. AngularJS provides a range of built-in services, along with the ability to create custom services as required. Services are also used for communication between application components through dependency injection (DI).

Service

  • Gives us the instance of a function (object) you just instantiated with the new keyword and you’ll add properties to this and the service will return this. When you pass the service into your controller, those properties on this 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() {
        //...
    }
});