Skip to content

Instantly share code, notes, and snippets.

@antoniocapelo
Created September 13, 2014 10:12
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 antoniocapelo/ff09216c153cf898b622 to your computer and use it in GitHub Desktop.
Save antoniocapelo/ff09216c153cf898b622 to your computer and use it in GitHub Desktop.
Factory creation in AngularJS
var app = angular.module('capeloMod', []);
//factory style, more involved but more sophisticated
app.factory('demoFactory', function() {
var publicValue = 0;
var privateValue = 0;
function apiFn() {
return this.publicValue++;
}
function apiFn2() {
return privateValue++;
}
return {
apiFn : apiFn,
apiFn2 : apiFn2,
publicValue : publiValue
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment