我目前有以下选择输入
<select
ng-model="people"
ng-options="capacity for capacity in Range(1, roomCapacity)"
class="form-control"
id="howmany"
ng-required="noOfPeopleRequired()">
</select>
范围是
$scope.Range = function(start, end) {
var result = [];
if (end === 1) {
result.push(1);
} else {
for (var i = start; i <= end; i++) {
result.push(i);
}
}
return result;
};
我正在观看一个int,当它改变时将roomCapacity的值设置为它,但不幸的是,我的选择
中的选项范围没有变化我该怎么做?
答案 0 :(得分:2)
Fo数组源,您可以使用以下表达式:
选择数组中值的标签
试试这个:
<强> JS 强>
.controller("myCtrl",function($scope){
$scope.Range = function(start,end){
var result = [];
if(end===1){
result.push(1);
}else{
for(var i=start;i<=end;i++){
result.push(i);
}
}
return result;
}
});
<强> HTML 强>
<div ng-controller="myCtrl">
<input type="text" id="roomCapacity" ng-model="roomCapacity"/>
<select
ng-model="people" ng-options="capacity as capacity for capacity in Range(1,roomCapacity)"
>
<option value="">Please select</option>
</select>
</div>