简体   繁体   English

如何从相同ng-options的其他用途中删除选定的ng-options

[英]How do I removed selected ng-options from other uses of same ng-options

I am trying to reuse an ng-options instance but remove the selected items from previous uses. 我正在尝试重用ng-options实例,但从以前的用途中删除了选定的项目。

I have a plunker started http://plnkr.co/edit/Fx7igqMjPsBQz1vtUlsM?p=preview 我有一个矮胖的人开始http://plnkr.co/edit/Fx7igqMjPsBQz1vtUlsM?p=preview

HTML HTML

  <body ng-controller="SelectController">
<div class="form-group col-md-3">
    <label for="select1">Select 1:</label>
    <select ng-model="newForm.select1" 
            ng-options="option.name as option.name for option in options" 
            class="form-control">
        <option value=""></option>
    </select>
</div>
<div class="row"><br></div>
    <div class="form-group col-md-3">
    <label for="select2">Select 2:</label>
    <select ng-model="newForm.select2" 
            ng-options="option.name as option.name for option in options" 
            class="form-control">
        <option value=""></option>
    </select>
</div>

JS JS

var app = angular.module('select', []);

app.controller('SelectController', function($scope) {

  $scope.options = [
   {name: 'Apple', id: '1'},
   {name: 'Orange', id: '2'},
   {name: 'Banana', id: '3'},
   {name: 'Pear', id: '4'},
 ];

});

So, for example if select 1 = Apples, I want to remove Apples from the ng-options in select 2. 因此,例如,如果select 1 = Apples,我想从select 2的ng-options中删除Apples。

What's the best way to do this? 最好的方法是什么? Thanks. 谢谢。

Second ng-options : 第二个ng-options

ng-options="... in options | filter: newForm.select1 && {name: '!' + newForm.select1}"

where newForm.select1 represents the model value of the first selection. 其中newForm.select1代表第一个选择的模型值。

See demo fiddle 演示小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM