Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.