如何禁用angularjs中的复选框

时间:2015-07-30 09:54:28

标签: angularjs checkbox angularjs-ng-disabled

我在视图页面上有一个复选框列表,用于发送不同角色的通知。我想最初禁用未选中状态的复选框。

我在视图中使用以下代码

<div ng-repeat="notification in NotificationList  | filter:{Media: item.Media}" ng-if="!collapsedNotification" ng-class="{'pad-top-4':($first)}" >
                                    <label for="NotificationLabel" class="col-sm-4 col-md-4 col-lg-4 control-label font-normal" title="{{notification.NotificationLabel}}">{{notification.NotificationLabel}}</label>
                            <div class="col-sm-1 col-md-1 col-lg-1"  style="line-height:35px;">
                                <span  class="col-lg-2 col-md-2 col-sm-2 item-padding ">
                                    <span class="default-pointer" ng-checkbox  ng-init="ToAdmin=false" ng-model='ToAdmin' ng-click="disableClick()" ng-disabled="ToAdmin"></input>

                                </span>

                            </div>
                            <div class="col-sm-1 col-md-1 col-lg-1" style="line-height:35px;">
                                <span  class="col-lg-2 col-md-2 col-sm-2 item-padding ">
                                    <span class="default-pointer" ng-checkbox ng-model='notification.ToNutritionist'></span>                                        
                                </span>
                            </div>
                            <div class="col-sm-1 col-md-1 col-lg-1"  style="line-height:35px;">
                                <span  class="col-lg-2 col-md-2 col-sm-2 item-padding ">
                                    <span class="default-pointer"  ng-checkbox ng-model='notification.ToPatient'></span>                                        
                                </span>
                            </div>
                                   </div>

如何使用angularjs禁用控制器中特定角色的复选框(处于未选中状态)?

1 个答案:

答案 0 :(得分:0)

您可以使用ng-disabled属性。

就像这个例子:

<input type="checkbox" ng-click="disable=!disable">

<input type="checkbox" ng-disabled="disable">