Skip to content

Instantly share code, notes, and snippets.

@nanlabsweb
Created August 18, 2016 12: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 nanlabsweb/ecbf098ad1790b4438858a0bcdf6af0d to your computer and use it in GitHub Desktop.
Save nanlabsweb/ecbf098ad1790b4438858a0bcdf6af0d to your computer and use it in GitHub Desktop.
POST - Form controller which uses a model to create/edit instances of it.
app.controller('formCtl', function($scope, $location, $routeParams, contactService) {
var contactId = ($routeParams.id) ? parseInt($routeParams.id, 10) : null;
$scope.contact = (contactId) ? contactService.get(contactId) : new Contact();
$scope.title = ($scope.contact.isNew()) ? 'Add New Contact' : 'Edit Contact';
$scope.types = CONTACT_TYPES;
$scope.saveAction = function() {
if ($scope.contactForm.$valid) {
contactService.save($scope.contact);
$location.path('/');
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment