在加载时默认选中Angularjs复选框,并在选中时禁用选择列表 [英] Angularjs checkbox checked by default on load and disables Select list when checked
问题描述
noob on stack overflow here。我正在处理一个具有转移工作功能的网页。这允许用户选中复选框将作业发送回办公室,或从所有可用的列表中选择技术人员。我的问题是如何设置复选框,以便在默认情况下检查页面加载并相应地禁用选择列表。这里是我目前的代码:
noob on stack overflow here. I am working on a webpage that has a transfer job function. This lets the user check a check-box to send the job back to the office, or select a technician from a list of all that are available. My question is how to setup the check-box so that it is checked by default when the page loads and have the select list disabled accordingly. Here is the code that I have for it at the moment:
<div ng-app="">
Send to Office: <input type="checkbox" ng-model="checked" ng-checked="true"><br/>
<select id="transferTo" ng-disabled="checked">
<option>Tech1</option>
<option>Tech2</option>
</select>
</div>
这里是一个jsfiddle它: http://jsfiddle.net/hugmungus/LvHJw/5/
and here is a jsfiddle for it: http://jsfiddle.net/hugmungus/LvHJw/5/
目前,框已选中,但列表未禁用。
Currently, the page loads with the check-box checked, but the list is not disabled. If you un-check then re-check the it, the list becomes disabled.
感谢您的帮助!
推荐答案
如果你使用ng-model,你不想使用ng-checked。而只是将模型变量初始化为true。通常你可以在一个控制器中管理页面(添加一个)。在你的小提琴中,我只是在ng-init属性中进行初始化以进行演示。
If you use ng-model, you don't want to also use ng-checked. Instead just initialize the model variable to true. Normally you would do this in a controller that is managing your page (add one). In your fiddle I just did the initialization in an ng-init attribute for demonstration purposes.
<div ng-app="">
Send to Office: <input type="checkbox" ng-model="checked" ng-init="checked=true"><br/>
<select id="transferTo" ng-disabled="checked">
<option>Tech1</option>
<option>Tech2</option>
</select>
</div>
这篇关于在加载时默认选中Angularjs复选框,并在选中时禁用选择列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!