使用 AngularJS ng-options 时如何禁用 select 元素的

2024-01-04

有没有办法禁用option in a select当我们填充时的元素options在 AngularJS 中使用 ng-options?

像这样:http://www.w3schools.com/tags/att_option_disabled.asp http://www.w3schools.com/tags/att_option_disabled.asp

您可以通过添加来做到这一点ng-disabled每一个<option>标签,但是如果我们使用ng-options指令中的select tag?


一种方法是忘记使用ng-options on the select元素,并将选项添加到 withng-repeat,那么你可以添加一个ng-disabled检查每个option.

http://jsfiddle.net/97LP2/ http://jsfiddle.net/97LP2/

<div ng-app="myapp">
    <form ng-controller="ctrl">
        <select id="t1" ng-model="curval">
            <option ng-repeat="i in options" value="{{i}}" ng-disabled="disabled[i]">{{i}}</option>
        </select>
        <button ng-click="disabled[curval]=true">disable</button>
    </form>
</div>

用于测试的最小控制器:

angular.module('myapp',[]).controller("ctrl", function($scope){
    $scope.options=['test1','test2','test3','test4','test5'];
    $scope.disabled={};
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 AngularJS ng-options 时如何禁用 select 元素的

随机推荐