Skip to content

Instantly share code, notes, and snippets.

@darkone23
Forked from cthecheese/myApp.js
Last active August 29, 2015 14:20
Show Gist options
  • Save darkone23/439f8e3b784374770cb5 to your computer and use it in GitHub Desktop.
Save darkone23/439f8e3b784374770cb5 to your computer and use it in GitHub Desktop.
var myApp = angular.module("myApp", []);
myApp.controller("contactsController", function($scope, contactsFactory){
$scope.contacts = contactsFactory.getContacts();
$scope.add = function(newContact){
contactsFactory.add(newContact);
$scope.newContact = contactsFactory.cleanContact();
$scope.contacts = contactsFactory.getContacts();
}
});
myApp.factory("contactsFactory", function(){
var contacts = [];
return {
add: contacts.push.bind(contacts),
getContacts: function() { return contacts; },
cleanContact: function() { return { name: "", email: "" }; }}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment