Skip to content

Instantly share code, notes, and snippets.

@wholypantalones
Last active August 29, 2015 14:19
Show Gist options
  • Save wholypantalones/a82d116566a1791305c3 to your computer and use it in GitHub Desktop.
Save wholypantalones/a82d116566a1791305c3 to your computer and use it in GitHub Desktop.
Dynamic form post using angular w/ action
<form class="form-horizontal" name="chkForm" method="post" action="/this/is/an/action/" ng-submit="processThis(chkForm.$valid,$event)" novalidate>
/* the processThis function fires before the form action submits so we can hijack it. Passing $event allows for event.preventDefault() to be used
in the function in order to stop the form posting. https://docs.angularjs.org/api/ng/directive/ngSubmit
*/
</form>
//in controller
$scope.processThis = function(isValid,e) {
if(isValid) {
e.preventDefault();
// send to a service instead of the action
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment