[英]Dropdown Checkbox Closes when Item Checked, and Doesn't Save Selection
I'm new to Javascript and AngularJS, and currently trying to implement a dropdown checkbox via a button (For a search filter). 我是Java和AngularJS的新手,目前正尝试通过按钮(用于搜索过滤器)实现下拉复选框。 I currently am able to have the dropdown appear, but when I check a checkbox, the dropdown immediately closes.
我目前能够显示下拉菜单,但是当我选中一个复选框时,下拉菜单会立即关闭。 The checked item is also not saved as checked when I open the dropdown again.
当我再次打开下拉菜单时,选中的项目也不会保存为选中状态。 Here's what I have in my tpl.html:
这是我的tpl.html中的内容:
<div class="input-group-btn">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown" bs-dropdown data-template-url="dropdown-template" data-placement="bottom-right">
<span class="fa fa-filter"></span>
</button>
<li class="dropdown-filter">
<script type="text/ng-template" id="dropdown-template">
<ul class="dropdown-menu">
<div>
<input type="checkbox" id="disabledStores">
<label for="disabledStores">Show Disabled Stores</label>
</div>
</ul>
</script>
</li>
</div>
What am I doing wrong? 我究竟做错了什么?
You need to save the value of the selection within a property and use the ng-model to bind to the html. 您需要将选择的值保存在属性中,并使用ng-model绑定到html。
In your controller must have : disabledStored : boolean = false.
在您的控制器中必须具有:
disabledStored : boolean = false.
And in your templare : <input type="checkbox" id="disabledStores" ng-model="disabledStored">
并且在您的模板中:
<input type="checkbox" id="disabledStores" ng-model="disabledStored">
When the checkbox is selected the value of the property will be true. 选中此复选框后,该属性的值将为true。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.