Javascript 尝试检查值是否未定义以控制已检查的ng设置
对于基于值是否未定义的复选框,我无法将Javascript 尝试检查值是否未定义以控制已检查的ng设置,javascript,angularjs,angularjs-ng-checked,Javascript,Angularjs,Angularjs Ng Checked,对于基于值是否未定义的复选框,我无法将ng checked设置为true。例如,在下面的代码中 <input class="custom-checkbox form-control" id="{{ point.pointId }}-{{ value }}" type="checkbox" ng-true-value="'{{ value }}'" ng-model="item.sections[inspectionSection.sectionShortName[point
ng checked
设置为true。例如,在下面的代码中
<input class="custom-checkbox form-control" id="{{ point.pointId }}-{{ value }}"
type="checkbox"
ng-true-value="'{{ value }}'"
ng-model="item.sections[inspectionSection.sectionShortName[point.pointId].value">
我似乎无法让它工作。我在
ng中尝试的任何内容都选中了
,要么选中所有复选框,要么不选中。非常感谢任何帮助 您可以通过使用三元运算符来实现这一点:
ng-checked="value !== undefined ? true : false"
我建议在这种情况下使用函数
ng-checked="isNotUndefined(value)"
// in the controller
isUndefined (value) {
return value !== undefined
}
明白,但我想我会加上它,因为这是你发布的解决方案的替代方案。关于这个问题有什么消息吗?
ng-checked="isNotUndefined(value)"
// in the controller
isUndefined (value) {
return value !== undefined
}