Created
November 9, 2015 06:53
-
-
Save maxkostinevich/720fa87f24bd1a9cb3f5 to your computer and use it in GitHub Desktop.
Angular - ng-submit access to form fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ''; | |
}; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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