Services

Services are often interpreted incorrectly. They can be easily confused with Ajax requests that are used with some backend service via the HTTP protocol. However, services are singleton, a function, or an object and can be used to hold and share data, through controllers, directives, filters, and other services. Also, you are free to create your own services; just register the service's name and the service factory function, with an Angular module. The service factory function creates the object or function and exposes the service to the rest of the AngularJS application.

var userModule = angular.module('userModule', []);
userModule.factory('server', function() {
  var serverServiceInstance;
  ...
  return serverServiceInstance;
});

A .service() and .factory() function always have a return statement. Being singleton had only one instance of a specific service per injector available in the entire life of the AngularJS application. Other services are constant, value, and provider; more about services can be found on the official documentation at https://docs.angularjs.org/guide/services.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.30.236