Skip to content

Instantly share code, notes, and snippets.

@alecklandgraf
Last active October 14, 2016 19:11
Show Gist options
  • Save alecklandgraf/8e71c08e3329d7c9d6c0931a5834f567 to your computer and use it in GitHub Desktop.
Save alecklandgraf/8e71c08e3329d7c9d6c0931a5834f567 to your computer and use it in GitHub Desktop.
angular factories vs services
angular.module('myModule', [])
.factory('myModuleFactory', function() {
const state = {
loaded: false,
};
const setLoaded = () => {
state.loaded = true;
};
return {
state,
setLoaded,
};
})
.service('myModuleService', function() {
const state = {
loaded: false,
};
const setLoaded = () => {
state.loaded = true;
};
this.state = state;
this.setLoaded = setLoaded;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment