Skip to content

Instantly share code, notes, and snippets.

@cadebward
Last active August 29, 2015 14:04
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 cadebward/ed4905fb0d5484fd8073 to your computer and use it in GitHub Desktop.
Save cadebward/ed4905fb0d5484fd8073 to your computer and use it in GitHub Desktop.
Modules Patterns
angular.module('app', [])
.factory('MyFactory', [function () {
// something factory-like
}])
var MODULE = (function () {
var bread = {};
// private
var loaf = true;
var privateMethod = function () {};
// public
bread.eat = function () {
console.log('You ate the bread! No more left! ');
loaf = false;
};
return bread;
})();
angular.module('app', [])
.factory('MyFactory', [function () {
var user = {};
var data = {name: 'cade', email: 'something@else.com', age: 24};
user.get = function () {
return data;
}
user.set = function (value, key) {
if (value && key) {
data[key] = value;
}
}
return user;
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment