I'm currently setting up a select
dropdown with an ng-options
. The dropdown is appearing correctly on the HTML page, but for some reason, when I choose an option, the variable specified by ng-model
is not updating in $scope
.
This is the HTML code:
<select ng-model="selected_ingredient"
ng-options="item as item.ingredient for item in available_ingredients"
ng-change="selectIngredient()">
<option value="">Add an ingredient...</option>
</select>
And this is the AngularJS code:
$scope.selectIngredient = function() {
if ( $scope.debug > 0 ) {
console.log( "Selected ingredient:" );
console.log( $scope.selected_ingredient );
}
};
When checking the console output after selecting a dropdown item (with $scope.debug
set to 1), it shows:
Selected ingredient:
undefined
My goal is for $scope.selected_ingredient
to hold the object item
that corresponds to the selected dropdown element. Can anyone point out what might be going wrong?