Angularjs 如何在更改复选框状态后使用ng checked获取更新的模型

Angularjs 如何在更改复选框状态后使用ng checked获取更新的模型,angularjs,Angularjs,我有选中复选框的特定条件,我正在使用条件运算符选中的ng中的函数逻辑。 这对我来说很好。 问题是,在提交模型值时,我没有得到ng检查值。 如何使ng检查值也得到修改?希望我能得到答案。 这是我尝试过的: <input type="checkbox" id="View" ng-model="module.View" ng-checked="((findViewCheckBoxIsChecked(module)) || (module.ViewAll))" ng-d

我有选中复选框的特定条件,我正在使用条件运算符选中的ng中的函数逻辑。 这对我来说很好。 问题是,在提交模型值时,我没有得到ng检查值。 如何使ng检查值也得到修改?希望我能得到答案。 这是我尝试过的:

<input type="checkbox" id="View" ng-model="module.View"
       ng-checked="((findViewCheckBoxIsChecked(module)) || (module.ViewAll))"
       ng-disabled="disableCheckBox(module)">
说明中明确指出,不应将其与
ng车型
一起使用

从文档中:

NGCHECK 如果
ngChecked
中的表达式为truthy,则在元素上设置checked属性

注意此指令不应与
ngModel
一起使用,因为这可能导致意外行为


更新
哦…我不知道这个…那么如何设置我必须检查的复选框的值呢?有什么想法吗

可以使用
ng change
指令计算同级复选框的值:

<input type="checkbox" id="ViewAll" ng-model="module.ViewAll"
       ng-change="updateCheckboxes(module)" />

<input type="checkbox" id="View" ng-model="module.View"
       ̶n̶g̶-̶c̶h̶e̶c̶k̶e̶d̶=̶"̶(̶(̶f̶i̶n̶d̶V̶i̶e̶w̶C̶h̶e̶c̶k̶B̶o̶x̶I̶s̶C̶h̶e̶c̶k̶e̶d̶(̶m̶o̶d̶u̶l̶e̶)̶)̶ ̶|̶|̶ ̶(̶m̶o̶d̶u̶l̶e̶.̶V̶i̶e̶w̶A̶l̶l̶)̶)̶"̶
       ̶n̶g̶-̶d̶i̶s̶a̶b̶l̶e̶d̶=̶ ̶"̶d̶i̶s̶a̶b̶l̶e̶C̶h̶e̶c̶k̶B̶o̶x̶(̶m̶o̶d̶u̶l̶e̶)̶"̶ 
       ng-disabled= "disableViewCheckBox"
       ng-change="updateCheckboxes(module)" />
出于性能原因,应避免将函数放入AngularJS表达式中。框架在每个摘要周期中调用这一次或多次。通过使用
ng change
指令,仅当用户更改输入时才会调用这些函数


当然,
ng change
函数仅在用户输入时调用。控制器在分配新模型值时还应调用
$scope.updatecheckbox
函数。

我想我不理解这个问题。另外,如果可能的话,发布
findViewCheckBoxIsChecked
的代码。是的,我添加了bro。你现在明白了吗?我在那里看到了很多条件。老实说,我们应该在上下文中看到这一点,例如,当问题出现时,
module
有什么值?如果你能创造一个。。。这会有很大帮助。moudle是模型对象bro。如果我单击一个复选框,则意味着还将选中另一个复选框,以查看此If-else代码。问题是第二个选中的复选框在提交后未反映在模型对象中。这是我的问题兄弟。哦…我不知道这个…那么如何设置我必须检查的复选框的值?有什么想法吗?我不明白你能不能详细解释一下我听不懂请
<input type="checkbox" id="ViewAll" ng-model="module.ViewAll"
       ng-change="updateCheckboxes(module)" />

<input type="checkbox" id="View" ng-model="module.View"
       ̶n̶g̶-̶c̶h̶e̶c̶k̶e̶d̶=̶"̶(̶(̶f̶i̶n̶d̶V̶i̶e̶w̶C̶h̶e̶c̶k̶B̶o̶x̶I̶s̶C̶h̶e̶c̶k̶e̶d̶(̶m̶o̶d̶u̶l̶e̶)̶)̶ ̶|̶|̶ ̶(̶m̶o̶d̶u̶l̶e̶.̶V̶i̶e̶w̶A̶l̶l̶)̶)̶"̶
       ̶n̶g̶-̶d̶i̶s̶a̶b̶l̶e̶d̶=̶ ̶"̶d̶i̶s̶a̶b̶l̶e̶C̶h̶e̶c̶k̶B̶o̶x̶(̶m̶o̶d̶u̶l̶e̶)̶"̶ 
       ng-disabled= "disableViewCheckBox"
       ng-change="updateCheckboxes(module)" />
$scope.updateCheckboxes = function(module) {
    module.View = (($scope.findViewCheckBoxIsChecked(module)) || (module.ViewAll));
    $scope.disableViewCheckbox = $scope.disableCheckBox(module);
};