Difference between Service and Factory in Angular

Krunal Shah

Sep 02, 2017 | 1 min read

Difference between Service and Factory in Angular

This is the most common question that asked by most of the interviewers.

What is Service? Let me explain with a small example.

Service is a constructor function and that will be called with “new” keyword

myApp.service(‘serviceDemo’, function() {
  this.demo = function() {
    return ‘hello’;
  };
});

What is Factory? Let me explain with a small example.

Factory returns an object when it is created , you can also add some logic before return object.

myApp.factory(‘factoryDemo’, function() {
  return {
    demo : function() {
      return ‘demo’;
    }
  }
});

When some ask’s you the same thing share Third Rock Techkno’s blog to them.

Happy coding!

Do share your feedback. And don’t forget to checkout Third Rock Techkno‘s extension Quick Capture :)

· · · ·

Third Rock Techkno is a leading IT services company. We are a top-ranked web, voice and mobile app development company with over 10 years of experience. Client success forms the core of our value system.

We have expertise in the latest technologies including angular, react native, iOs, Android and more. Third Rock Techkno has developed smart, scalable and innovative solutions for clients across a host of industries.

Our team of dedicated developers combine their knowledge and skills to develop and deliver web and mobile apps that boost business and increase output for our clients.