Factory can return anything which can be a class (constructor function), instance of class, string, number or boolean. If you return a constructor function, you can instantiate in your controller.
Factory
Gives us the function's return value i.e. you just create an object, add properties to it, then return that same object. When you pass this service into your controller, those properties on the object will now be available in that controller through your factory. (Hypothetical Scenario)
Singleton
Usage: if you're using an object, you could use the factory provider.
Syntax:
module.factory('factoryName', function);
AngularJS .factory
module.factory('MyFactory', function() {
var factory = {};
factory.method1 = function() {
//...
}
factory.method2 = function() {
//...
}
return factory;
});