Skip to content

Instantly share code, notes, and snippets.

@siongui
Created February 15, 2013 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siongui/4964109 to your computer and use it in GitHub Desktop.
Save siongui/4964109 to your computer and use it in GitHub Desktop.
/**
* @see http://docs.angularjs.org/guide/dev_guide.services.creating_services
* Lastly, it is important to realize that all Angular services are application singletons.
* This means that there is only one instance of a given service per injector.
*/
// code snippet from: http://stackoverflow.com/a/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 return "Hi " + name + "!";
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment