Services are the building blocks that Angular provides for the definition of the business logic of our applications. In AngularJS 1.x, we had three different ways for defining services:
// The Factory method module.factory('ServiceName', function (dep1, dep2, …) { return { // public API }; }); // The Service method module.service('ServiceName', function (dep1, dep2, …) { // public API this.publicProp = val; }); // The Provider method module.provider('ServiceName', function () { return { $get: function (dep1, dep2, …) { return { // public API }; } }; });
Although the first two syntactical variations provide similar functionality, they differ in the way the registered directive will be instantiated. The third syntax allows further configuration of the registered provider during configuration time.