---
title: "What is the difference between a factory and a service in AngularJS?"  
description: "What is the difference between a factory and a service in AngularJS?"  
author: "Ravi Vishwakarma"  
published: 2025-03-30  
updated: 2025-04-01  
canonical: https://www.mindstick.com/forum/161388/what-is-the-difference-between-a-factory-and-a-service-in-angularjs  
category: "angular js"  
tags: ["javascript", "angular js"]  
reading_time: 2 minutes  

---

# What is the difference between a factory and a service in AngularJS?

What is the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between a [factory](https://www.mindstick.com/blog/304231/factory-vs-service-in-angularjs-which-one-better) and a [service](https://www.mindstick.com/articles/105963/online-thesis-writing-service-for-college-kids-with-disabilities) in AngularJS?

## Replies

### Reply by Khushi Singh

The [AngularJS framework](https://www.mindstick.com/articles/1493/basics-of-angular-js) provides two components, called factories and services, which serve to develop reusable components that contain business logic and manage data retrieval. The two methods generate objects, yet they have distinct approaches for instantiation and object return. A factory serves as a function that develops explicit object returns so developers can implement their customization before object output. The design allows developers to modify returned objects either through modified creation or dynamic construction. AngularJS uses the service constructor function instantiation through the new keyword operation. Services provide an alternative to explicit object returns because they add properties and methods to the concept while enhancing its object-oriented functionality.

The final decision between service and factory elements revolves around your preferred approach to creating and instantiating objects. The creation process of factories provides extensive control, whereas service methods allow for a streamlined, standardized design. The definition of a simple math operation, as shown by a factory, appears below:

```javascript
angular.module('myApp', [])
 .factory('MathFactory', function() {
   return {
     add: function(a, b) {
       return a + b;
     }
   };
 })
 .controller('MathController', function($scope, MathFactory) {
   $scope.result = MathFactory.add(5, 10);
 });
```

`MathFactory` provides an explicit object return, yet the service logic would utilize the returned object. Services should be utilized for constructing reusable logic through constructors, while factories better serve dynamic object-based creation. AngularJS accepts both methods for value creation, but the implementation choice depends on the requirements of the particular application.


---

Original Source: https://www.mindstick.com/forum/161388/what-is-the-difference-between-a-factory-and-a-service-in-angularjs

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
