问题描述
我需要能够以编程方式将一个复选框设置为在事件发生时取消选中(该事件实际上是被隐藏的模式).我需要使当前的 ng-change
函数具有相同的参数.
I need to be able to programmatically set a checkbox to unchecked when an event happens (the event is actually a modal being hidden). I need to keep the current ng-change
function with the same parametes.
我有一个复选框元素:
<input type="checkbox" ng-change="change(ordered, $index, {{part.id}}, {{part.vehicle_id}}, '{{part.ordered_from}}')" ng-true-value="1" ng-false-value="0" ng-model="ordered" name="part-ordered" />
还有我的JS:
$scope.change = function(value, part_index, id, vehicle_id, ordered_from_val) {
if (modal_hidden_event) {
// UNCHECK CODE.
}
}
我不太确定要搜索的内容或文档的哪些领域对我有帮助.
I am not too sure what to search for or what area of the docs will help me.
推荐答案
我不确定modal_hidden_event的来源,我假设它只是一个占位符.我还清理了HTML中的change函数,因为不需要插值,因为这些值不存在:
I am not sure where modal_hidden_event is coming from, I am assuming it is just a placeholder here. I've also cleaned up your change function in the HTML, as it does not need to be interpolated, as the values exist without:
使用 ng-checked :
HTML
<input type="checkbox"
ng-change="change(ordered, $index, part.id, part.vehicle_id, part.ordered_from)"
ng-true-value="1"
ng-false-value="0"
ng-model="ordered"
ng-checked="checkedStatus"
name="part-ordered" />
JS
$scope.checkedStatus = true;
$scope.change = function(value, part_index, id, vehicle_id, ordered_from_val) {
if (modal_hidden_event) {
$scope.checkedStatus = false;
}
}
我还建议仅将零件传递给函数,然后可以在其中获取每个属性:
I also recommend just passing the part into the function, and you can grab each property there:
HTML
"change(ordered, $index, part)"
$ scope.change = function(value,part_index,part){
$scope.change = function(value, part_index, part) {
JS
$scope.change = function(value, part_index, part) {
var part_id = part.id,
vehicle_id = part.vehicle_id,
ordered_from_val = part.ordered_from;
if (modal_hidden_event) {
$scope.checkedStatus = false;
}
}
这篇关于复选框和ng-change.需要取消检查是否存在条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!