我正在使用带有 ng 模型、ng-true-value 和 ng-false-value 的复选框。 它工作正常,但是当它的值变为 1 并且默认选中时,需要单击 2 次才能更改该值。
有什么方法可以通过第一次点击来做到这一点
代码示例:
<input type="checkbox" ng-checked="CreateUpdateCat.IsDiscussionAllowed=='1'" ng-model="CreateUpdateCat.IsDiscussionAllowed" ng-true-value="1" ng-false-value="2" >
Controller 代码:
angular.forEach($scope.CategoryData,function(v,k){
if(v.id == id)
{
$scope.CreateUpdateCat = {IsDiscussionAllowed:v.IsDiscussionAllowed,Name:v.Name};
};
});
这是 plunkr 网址:https://plnkr.co/edit/JApepZfvNrlqDj9vine0?p=preview 默认值为 1,但复选框未显示已选中
最佳答案
要么使用 ng-checked
要么 ng-model
否则 Angular 会感到困惑。并且您可能会得到意想不到的结果。
仅使用一个指令 ng-checked
或 ng-model
关于javascript - 使用 ng true 和 ng false 时,Angular ng 模型需要点击 2 次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42435502/