Hi, The basic difference between factory and service is that factory is a function that return the object, while service is the constructor function of the object which is instantiated with the new keyword. In your scenario, when you change factory to service, you create a new constructor function. Returning a value from constructor function has its own implications which are discussed here:
http://www.gibdon.com/2008/08/javascript-constructor-return-value.html Your scenario can be representated as follows: function currencyConverter(){ return { currencies: currencies, convert: convert }; } //In case of factory var currencyConverterObj = currencyConverter(); //In case of service var currencyConverterInstance = new currencyConverter(); In both the cases currencyConverterObj and currencyConverterInstance have the intended properties but the service case is more of a side effect in my opinion. Regards, Vaibhav Gupta On Thursday, 26 November 2015 05:38:13 UTC+5:30, binaryMoods wrote: > > I'm just looking at Angular conceptual overview. Their example has the > following line of code: > > angular.module('finance2', []).factory('currencyConverter', function() > > I've changed factory for service: angular.module('finance2', > []).service('currencyConverter', function() -- and still works as if > nothing happened. So no big deal here? > > Plunker: http://plnkr.co/edit/4QXbWCgzxPV8Q4FaOuUm?p=preview > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
