I have seen both angular.factory() and angular.service() used to declare services; however, I cannot find angular.service anywhere in official documentation.
Simply put ..
const user = {
firstName: 'john'
};
// Factory
const addLastNameFactory = (user, lastName) => ({
...user,
lastName,
});
console.log(addLastNameFactory(user, 'doe'));
// Service
const addLastNameService = (user, lastName) => {
user.lastName = lastName; // BAD! Mutation
return user;
};
console.log(addLastNameService(user, 'doe'));