如何仅根据freqValue从html设置min,max值。
<input type="number" min="0" max="100" ng-model="interval" /> <select ng-model="freqValue" ng-options="f.key as f.value for f in freq"> </select>
答案 0 :(得分:1)
您可以将包含这些频率值的地图作为其键存储每个频率的min
和max
值,以便在模型更改时,angularjs将重新绑定min
和基于地图索引的max
值,即freqValue
变量。
例如:
控制器:
$scope.map = {
'1': { min: 1, max: 20 },
'2': { min: 1, max: 45 },
'3': { min: 1, max: 100 },
};
模板:
<input type="number"
min="{{ map[freqValue].min }}"
max="{{ map[freqValue].max }}"
ng-model="interval" />
<select
ng-model="freqValue"
ng-options="f.key as f.value for f in freq">
</select>
答案 1 :(得分:0)
试试这个
(function() {
var app = angular.module('app', []);
app.controller('main', ['$scope', function($scope) {
var vm = this;
vm.freq = [{key:1},{key:2},{key:3}]
vm.setMinMax = function() {
if (vm.freqValue == 1) {
vm.min = 1;
vm.max = 20;
}
if (vm.freqValue == 2) {
vm.min = 1;
vm.max = 45;
}
if (vm.freqValue == 3) {
vm.min = 1;
vm.max = 100;
}
}
}]);
})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<html lang="en" ng-app="app">
<body ng-controller="main as vm">
<select ng-model="vm.freqValue" ng-options="f.key as f.key for f in vm.freq" ng-change="vm.setMinMax()">
<option value="">select</option>
</select>
<input type="number" ng-min="{{vm.min}}" max="{{vm.max}}" ng-model="interval" />
</body>
</html>