What is the factory method?
The factory method, used for creating a directive, gets invoked when the compiler matches the directive for the first time. This function can be invoked by
module.factory( 'factoryName', function );
When you declare factoryName as an injectable argument, you will get the value which will be returned by invoking the function reference passed to the module.factory.