我正在尝试向从 ng-model 接收它的变量添加一个值。
这是HTML:
<div ng-form="amountForm" class="form-group" id="inputField">
<input value="1" type="number" placeholder="1" ng-model="itemAmount" ng-maxlength="2" required>
</div>
<div ng-form="nameForm" class="form-group">
<input value="" type="text" placeholder="Name of Item" ng-model="itemName" ng-maxlength="10" required>
</div>
<select ng-model="currentDependent">
<option ng-repeat="item in items" value="{{item.dependentOn}}" ng-selected="currentDependent == item.dependentOn">{{item.name}}</option>
</select>
这是 Angular($scope.itemAmount 和 $scope.itemName 有效):
$scope.items = [];
$scope.addItem = function () {
console.log($scope.itemAmount + ", " + $scope.itemName + ", " + $scope.currentDependent);
$scope.items.push({
amount: $scope.itemAmount,
name: $scope.itemName,
showMe: false,
dependentOn: $scope.currentDependent
});
};
控制台上似乎没有打印任何内容:
所以唯一不起作用的是Select中的ng-model。下拉列表显示正确的值。如何获取下拉列表中选择的值以在控制台中打印?
注意:为了清楚起见,我省略了 http.post 代码。