Services in angularjs

Angular services

Services In AngularJS

Angular JS  object has properties and methods, just like any other JavaScript object has a lot of built-in services. Angular is simply an object that provides some sort of service that can be reused within an angular application. Services $http , $location, $scope, $timeout, $interval, $log, $filter.
It was created in Three Ways
1. Factory
2. Service and
3. Provider.
Angular First, create a main module named app using this syntax.
var app = angular.module(‘myApp’, []);

Factory:

It can be injected into the components like controller, service, filter or directive.
We use the factory method to create an object, add properties to it and return the same object.
angular can create a service is by using the Module’s Factory API.
The general syntax for using Factory service.
app.factory(‘factoryName’,function(){
       return factoryObj;
  });

Service:

Object instance becomes the service object that AngularJS registers and is injected to the required components.
You will be provided with an instance of the function passed to the service.
 The general syntax for using Service.
app.service(‘serviceName’,function(){ });

Provider:

Providers are used when you want to provide module-wide configuration for your service object before making it available.
It returns value by using $get() function. Providers are the only service you can pass into your .config() function.
The general syntax for creating and configuring a Provider.
  // syntax for creating a provider
app.provider(‘providerName’,function(){ });
//syntax for configuring a provider
app.config(function(providerNameProvider){});
For AngularJS Course Details Click Here
Please follow and like us:
500

1 thought on “Services in angularjs

Leave a Reply

Your email address will not be published. Required fields are marked *