我一直试图过滤基于单选按钮选择显示在下拉列表中的选项列表。当过滤选择列表时更新默认选择选项
<div>
<div ng-controller="sampleCtrl">
<label>
<input type="radio" name="type" ng-value="1" ng-model="selectedType" />A</label>
<label>
<input type="radio" name="type" ng-value="2" ng-model="selectedType" />B</label>
<select ng-model="selectedOption" ng-options="option.id as option.name for option in options | filter:{type:selectedType}">
<option value=""><Select></option>
</select>
<hr/>
<div>Type: {{selectedType}}</div>
<div>Option: {{selectedOption}}</div>
</div>
</div>
function sampleCtrl($scope) {
$scope.selectedType = 1;
$scope.selectedOption = 0;
$scope.options = [{
id: 1,
name: 'bread',
type: 1
}, {
id: 2,
name: 'sugar',
type: 2
}, {
id: 3,
name: 'tea',
type: 1
}, {
id: 4,
name: 'coffee',
type: 2
}, {
id: 5,
name: 'butter',
type: 2
}];
}
这里是jsFiddle
我有一个默认的'应每个用户改变类型时显示的选项。 现在它根据类型筛选我的选项。但是,当过滤器更改为时,它不会更改我的模型。
请大家帮忙。
谢谢。
我无法理解你的问题 - 你的意思是指出哪里,从B选项更改为A时,选择模型不复位,仍然保持之前选择的行为? – callmekatootie
是的。这就是我的意思。对不起,如果我的问题不够清楚。 – vaibinewbee