Skip to content

Instantly share code, notes, and snippets.

@maxkostinevich
Created November 9, 2015 06:53
Show Gist options
  • Save maxkostinevich/720fa87f24bd1a9cb3f5 to your computer and use it in GitHub Desktop.
Save maxkostinevich/720fa87f24bd1a9cb3f5 to your computer and use it in GitHub Desktop.
Angular - ng-submit access to form fields
myApp.controller('myCtrl', function( $scope ) {
$scope.addNewItem = function ( event ) {
var formElement = angular.element(event.target);
var itemIndex = formElement[0].itemIndex.value;
var optionName = formElement[0].optionName.value;
var newOption = {
'name': optionName,
};
if ( !newOption.name) {
return;
}
$scope.items[itemIndex].options.push(newOption);
formElement[0].optionName.value = '';
};
});
<form ng-submit="addNewItem( $event )">
<input type="hidden" name="itemIndex" value="{{itemIndex}}">
Floor Options<br />
Option Name: <input type="text" name="optionName"><br>
<input type="submit" class="button" value="Add Option" >
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment