Skip to content

Instantly share code, notes, and snippets.

@JediMindtrick
Created November 17, 2014 12:01
Show Gist options
  • Save JediMindtrick/8b2532de1a92afa49e83 to your computer and use it in GitHub Desktop.
Save JediMindtrick/8b2532de1a92afa49e83 to your computer and use it in GitHub Desktop.
AngularTheBasics-Service Definition
//see this stackoverflow question
// http://stackoverflow.com/questions/13762228/confused-about-service-vs-factory/13763886#13763886
app.service('myService', function() {
// service is just a constructor function
// that will be called with 'new'
this.sayHello = function(name) {
return "Hi " + name + "!";
};
});
app.factory('myFactory', function() {
// factory returns an object
// you can run some code before
return {
sayHello : function(name) {
return "Hi " + name + "!";
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment