$http
, but a user needs to create own services for most applications. Controllers, Directive, and Filters can call the functions as on when required.
Angular services are categorized into two types:
$http
, $route
, $window
, $location
etc. Every service is responsible for a particular task. For example, $http
is responsible to call AJAX to get the server data without reloading a page. In-build services are always prefixed with $ symbol. $window
,$http
,$location
, $route
. These services can be utilized inside any controller by simply announcing them as dependencies.
[javascript]
module.controller('SPController', function($http){
//...
});
module.controller('SPController', function($window){
//...
});
[/javascript]
MyService
is defined in two different ways. Note that, for .service
service, methods are created using this.methodname. And in .factory,
a factory object is created and the methods are assigned to it.