Differences
AngularJs Factory and Services. References: https://blog.thoughtram.io/angular/2015/07/07/service-vs-factory-once-and-for-all.html The difference between services and factories we can define a service like this: app . service ( 'MyService' , function () { this . sayHello = function () { console . log ( 'hello' ); }; }); .service() is a method on our module that takes a name and a function that defines the service. app . factory ( 'MyService' , function () { return { sayHello : function () { console . log ( 'hello' ); } } }); .factory() is a method on our module and it also takes a name and a function, that defines the factory. a service is a constructor function where as a factory is Not .T here’s ' this ' code that calls Object.create() with the service constructor function, when it gets instantiated. However, a factory function is really just a function that gets called, ...
Comments
Post a Comment