.
.
<select ng-model="curopt"
ng-options="option.name for option in options">
</select>
<input type="text" ng-model="newopt"
ng-show="curopt.name == 'New'"
ng-keypress="newOption($event)">
ng-show . ng-keypress, .
...
$scope.newOption = function(event) {
if (event.which == 13) {
$scope.options.push({ name : $scope.newopt, value : $scope.newopt });
$scope.newopt = '';
}
}
Since our input selection options are bound to $scope.options, we can simply add the value of our text input to the array, and angular will handle the update for us due to data binding.
source
share