2017-08-17 75 views

回答

1

可以具有與這些頻率值作爲它的密鑰存儲用於minmax值的地圖每個頻率,以便在模型更改時,angularjs將根據地圖索引(即freqValue變量)重新綁定minmax值。

例如:

控制器:

$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> 
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>

相關問題