Services in angularjs

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’, []);


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.
       return factoryObj;


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(){ });


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
For AngularJS Course Details Click Here

This Post Has One Comment

  1. Thank for sharing this nice Information to learn AngularJS course.

Leave a Reply

Close Menu