如何观看两个选择框的模型(不使用 ng Change)(如果选择)应计算平均值并在文本字段中显示答案:例如
HTML 我:
<select ng-model="box1" ng-options="item for item in boxA"></select>
Controller :
$scope.boxA=[1,2,3,4,5];
HTML II:
<select ng-model="box2" ng-options="item for item in boxB"></select>
Controller :
$scope.boxA=[6,7,8,9,10];
文本框:
<input type="text" ng-model="answer">
最佳答案
如果您不想使用 ng-change,我的建议是每隔一段时间检查 Controller 中的值。
$interval(function() {
if($scope.box1 && $scope.box2) {
$scope.answer = (parseInt($scope.box1) + parseInt($scope.box2))/2
}
}, 1000);
关于javascript - 获取 Angular js中两个下拉值的平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28412039/