简体   繁体   English

如何基于具有相同选项值的另一个选择元素禁用选择元素中的选项?

[英]How to disable the options in select element based on another select element with same option values?

I have to disable the slect options based on value selected in another select. 我必须基于另一个选择中选择的值禁用选择选项。

<select   ng-model="myval" ng-options="lst as lst.txt  for lst in valuedata track by $index" ></select>


   <select   ng-model="myval" ng-options="lst as lst.txt  for lst in valuedata track by $index" ></select>

here I get same data,but my requirement is,if I select two in first dropdown I need to disable the values less than two in second dropdown and If i select two in dropdown two I need to disable the values greater than two in first dropdown. 在这里我得到相同的数据,但是我的要求是,如果我在第一个下拉列表中选择两个,则需要在第二个下拉列表中禁用小于两个的值;如果在下拉列表中选择两个,则需要在第一个下拉列表中禁用大于两个的值。

Any help would be appreciated. 任何帮助,将不胜感激。

Try following code: 尝试以下代码:

<script>
var app = angular.module('myApp1', []);
app.controller('myCtrl', function($scope) {
    //get your value and compare
});
var app2 = angular.module('myApp2', []);
app2.controller('myCtrl2', function($scope) {
    //get your value and compare
});

</script>

You can achieve this by disable when syntax of angular 1.4+ version. 您可以通过disable when angular 1.4+版本的语法来实现此目的 Read Doc. 阅读文件

In your problem, I suggest to have 2 different ng-model properties( though you can achieve this by single prop as well )., you can do like: 在您的问题中,我建议您具有2个不同的ng-model属性( 尽管您也可以通过单个prop来实现 )。您可以这样做:

    <select ng-model="data.first" ng-options="lst.txt as lst.txt disable when lst.txt > data.second for lst in valuedata">
    </select>

    <select ng-model="data.second" ng-options="lst.txt as lst.txt disable when lst.txt < data.first for lst in valuedata">
   </select>

Here is working fiddle . 这是工作的小提琴

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

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