2

What, if anything, does it have to do with the factory pattern?

Or if nothing, then why is it called a factory? It seems more like a singleton to me.

richard
  • 11,439
  • 22
  • 92
  • 148

1 Answers1

1

My guess is that a factory can be used to create factory functions

app.factory('MyFactory', function() {
  // The returned function is available by injecting MyFactory
  // into other components
  return function() {
    return 'Something created by the factory';
  };
});

This can be used, for example, in a controller

app.controller('MyController', function(MyFactory) {
  var myObj = MyFactory();
  // myObj is 'Something created by the factory'
});

(You can do something like this using service as well. I think you just have to live with the fact there is almost complete overlap between what you can do with factory and service)

Michal Charemza
  • 24,475
  • 11
  • 89
  • 143