Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
AngularJS

Creating Custom Services in AngularJS

Register app services with .service() for shared business logic.

Creating Custom Services in AngularJS — a practical guide to AngularJS custom services with clear examples you can reuse in real projects.

AngularJS Tutorial Series (45/99). Prefer one article? Read the complete AngularJS tutorial.

Short description

Inject $http and other deps via array annotations for minification safety.

service()

angular.module('myApp').service('ItemService', ['$http', function ($http) {
  this.list = function () {
    return $http.get('/api/items').then(function (res) { return res.data; });
  };
}]);

Leave a reply

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