I am new to Angular services/factory.
This is my simple angular service & factory. Both outputs the same.
//defining service
app.service('myService', function () {
this.name = '';
this.setName = function (custName)
{
this.name = newName;
return this.name;
};
});
//defining factory
app.factory('myFactory', function () {
var serviceObj = {};
serviceObj.name = '';
serviceObj.setName = function (custName) {
serviceObj.name = newName;
};
return serviceObj;
});
I have gone few links to get understanding of service vs factory, but I couldn't get it clear.
For the above snippet, what should I use, factory or service.
In general scenario, when should I use factory or service?
Looking for some clear & concise answer.