Services and Factory are important parts of Angular 1x where we communicate with a remote server for data. We used to define APIs call inside factory functions that controllers calls for fetching data from the servers:
// Factory method in Angular 1x angular.module('wedding.services', []) // DI of $http for HTTP calls to servers // $q for promises .factory('CategoryService', function ($http, $q) { var catalog = {}; catalog.getCategories = function () { // here we will call APIs } })
Now you will see how we have migrated our code to Angular 4 providers. The same getCategories() method that was inside factory in Angular 1, will now be moved inside the CategoryData() class in Angular 4:
// Provider in Angular ...