【发布时间】:2018-02-14 16:05:51
【问题描述】:
大家好,我是 angularjs 的新手,有人可以帮帮我吗?当我单击一个按钮时,我需要的所有东西都是要检查的 ng-repeat 列表中的第一个复选框。我做错什么了吗?这是我的代码:
复选框
<fieldset class="top5">
<legend title="Categories"><span class="info blackLabelUpper"><b>Dish Categories</b><span class="TextCtrlReqBgImage"> </span></span></legend>
<span class="checkbox-list" ng-repeat="dishType in dishTypes">
<input type='checkbox' ng-click="toggleDishType(dishType)" ng-model="dishType.checked" value="{{dishType}}" ng-checked="selectedDish.Type.indexOf(dishType) > -1">
{{dishType}}<br />
</span>
</fieldset>
按钮
<kendo-button id="btnNewDish" class="k-primary" ng-click="onNewDishClick(true)">
<i class="fa fa-plus fa-lg" aria-hidden="true"></i>New Dish
</kendo-button>
功能
scope.onNewDishClick = function (showNewDIshMessage) {
scope.dishTypes[0].dishType = true;
}
【问题讨论】:
-
试试这个
<input type='checkbox' ng-click="toggleDishType(dishType)" ng-model="dishType.checked" value="{{dishType.checked}}" /> -
感谢 Ramesh 我需要在单击按钮时选中列表中的第一个复选框。我还有其他需要取消选中的角色。
-
<input type='checkbox' ng-click="toggleDishType(dishType)" ng-model="dishType.dishType " value="{{dishType.dishType }}"因为你保存在函数中的dishType属性中 -
谢谢 Karan 我试过这个,但我没有工作。如果我单击按钮,该操作应该会发生。我不会默认选中复选框。
-
代替 ng-model="dishType.checked" 试试这个 ng-model="dishType"。
标签: javascript angularjs checkbox angularjs-ng-repeat