【发布时间】:2018-05-11 13:49:05
【问题描述】:
这是我的 angularjs 代码
<label class="switch">
<input
type="checkbox"
ng-model="question.questionId"
ng-change="questionStatusChange(question.questionId,!question.active)"
ng-checked="question.active" >
<span class="slider round"></span>
</label>
ng-change 正在从 unchecked 触发到 checked 状态
但
ng-change="questionStatusChange(question.questionId,!question.active)" 无法从 checked 到 unchecked 状态。
我正在尝试启用或禁用表记录。
$scope.questionStatusChange = function(questionId,status) {
console.log(status);
}
我正在使用这个切换: https://www.w3schools.com/howto/howto_css_switch.asp
【问题讨论】:
-
ng-checked 或 ng-model。对于 ng-model,您可以添加 ng-change。切勿在同一输入上同时使用两者。
-
@PetrAveryanov 在初始循环中我希望它基于该值作为“已检查/未检查”,因此我使用了 ng-checked。能否请您给出代码示例。
-
为什么要将
id绑定到带有ng-model="question.questionId"的复选框?在我看来,这应该在 html 中的其他位置,例如<label> -
我不需要 ng-model 但如果没有 ng 更改就无法正常工作,这就是我写的原因
标签: javascript angularjs switch-statement toggle