Created
February 15, 2013 22:29
-
-
Save siongui/4964109 to your computer and use it in GitHub Desktop.
From: confused about service vs factory
http://stackoverflow.com/questions/13762228/confused-about-service-vs-factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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