选中复选框后,ng-change第一次不起作用

时间:2019-03-29 10:15:17

标签: angularjs

当我为用户列表功能单击详细信息时,如下面的屏幕所示,我已经为用户构建了带有设置列表功能的应用。但是当我取消选中时,列表函数不会删除之前定义的函数。请帮助我,谢谢!

查看:HTML

<ul class="todo-list-module" ng-repeat="func in funcs">
    <li class="todo-list-item-module">
        <div class="panel-body">
            <div class="col-md-12">
                <div class="panel-heading-{{func.Components | lowercase}}">
                    <div class="row progress-labels">
                        <span class="pull-right clickable panel-toggle panel-button-tab-left">
                            <em class="fa fa-toggle-up"></em>
                        </span>{{func.ModuleName}}
                    </div>
                </div>
                <div class="panel-body {{func.Components | lowercase}}">
                    <ul class="todo-list" ng-repeat="fu in func.Funcs">
                        <li class="todo-list-item">
                            <div class="checkbox">
                                <input id="checkbox-{{fu.ModuleCode}}"
                                       type="checkbox"
                                       ng-checked="isChecked(fu.FunctionId)"
                                       ng-model="bool"
                                       ng-change="sync(bool, fu)">
                                <label for="checkbox-{{fu.ModuleCode}}">{{fu.FunctionName}}</label>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </li>
</ul>

AngularJS:

$scope.isChecked = function (FunctionId) {
    var match = false;
    for (var i = 0; i < $scope.user.Functions.length; i++) {
        if ($scope.user.Functions[i].FunctionId == FunctionId) {
            match = true;
        }
    }
    return match;
};
$scope.sync = function (bool, fu) {
    if (bool) {
        $scope.user.Functions.push(fu);
    } else {
        for (var i = 0; i < $scope.user.Functions.length; i++) {
            if ($scope.user.Functions[i].FunctionId == fu.FunctionId) {
                $scope.user.Functions.splice(i, 1);
            }
        }
    }
};

0 个答案:

没有答案