繁体   English   中英

如何从angularjs中的其他选择列表中禁用所选选项?

[英]How to disable the selected option from other select list in angularjs?

我正在设置一个选择列表从年份和到年份通过ng-repeat及其工作正常我需要的是当我从列表中选择一个选项时,它应该从另一个列表中禁用。 如何使用Angularjs?

谢谢。

HTML

<li> 
    <select class="form-control">
        <option value="" selected disabled>From Year</option>
        <option ng-repeat="option in selectedYear" >{{option.years}}</option>
    </select>
</li>

<li>
    <select class="form-control">
        <option value="" selected disabled>To Year</option>
        <option ng-repeat="option in selectedYear" >{{option.years}}</option>
    </select>
</li>

JSON

{"json1":"[{\"years\":2018},{\"years\":2017},{\"years\":2016},{\"years\":2015}]

运行以下代码段并让我知道,这是你想要的

 angular.module("app", []) .run(($rootScope) => { $rootScope.selectedYears = [] $rootScope.years = [{ "years": 2018 }, { "years": 2017 }, { "years": 2016 }, { "years": 2015 }] }) 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script> <div ng-app="app"> <li> <select class="form-control" ng-model="selectedYears[0]"> <option value="" selected disabled>From Year</option> <option ng-repeat="option in years" ng-disabled="selectedYears.indexOf(option.years) !== -1 && selectedYears.indexOf(option.years) !== 0" ng-value="{{option.years}}"> {{option.years}} </option> </select> </li> <li> <select class="form-control" ng-model=selectedYears[1]> <option value="" selected disabled>To Year</option> <option ng-repeat="option in years" ng-disabled="selectedYears.indexOf(option.years) !== -1 && selectedYears.indexOf(option.years) !== 1" ng-value="{{option.years}}"> {{option.years}} </option> </select> </li> </div> 

暂无
暂无

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

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