如何禁用选择<选项>采用NG选项是什么时候? [英] How to disable select <option> when using ng-options?

查看:107
本文介绍了如何禁用选择<选项>采用NG选项是什么时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来禁用在选择在AngularJS的选项?

Is there a way to disable an option in a select in AngularJS?

http://www.w3schools.com/tags/att_option_disabled.asp

您可以通过手动添加 NG-停用每个&LT做标签,但有如果我们使用了办法做到这NG选项指令在选择标签?

You can do it by manually adding ng-disabled to each <option> tag, but is there a way to do it if we are using the ng-options directive in the select tag?

推荐答案

要做到这一点(现在我们已经想通了这个问题)的方法之一是使用放弃 NG-选项选择元素,并与NG-重复添加的选项,那么我们可以添加一个 NG-停用检查每个选项

One way to do this (now that we've figured out the question) is to forgo using ng-options on the select element, and add the options in with ng-repeat, then we can add an ng-disabled check on each option.

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>

进行测试的最小控制器:

a minimal controller for testing:

angular.module('myapp',[]).controller("ctrl", function($scope){
    $scope.options=['test1','test2','test3','test4','test5'];
    $scope.disabled={};
})

这篇关于如何禁用选择&LT;选项&GT;采用NG选项是什么时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆