AngularJS: ng-model not binding to ng-checked for checkboxes

后端 未结 6 865
别跟我提以往
别跟我提以往 2020-11-22 08:06

I referred to this before asking this question.

AngularJs doesn't bind ng-checked with ng-model

If ng-checked is evaluated to true

6条回答
  •  隐瞒了意图╮
    2020-11-22 08:33

    The ng-model and ng-checked directives should not be used together

    From the Docs:

    ngChecked

    Sets the checked attribute on the element, if the expression inside ngChecked is truthy.

    Note that this directive should not be used together with ngModel, as this can lead to unexpected behavior.

    — AngularJS ng-checked Directive API Reference


    Instead set the desired initial value from the controller:

    
        Testing
    Testing 2
    Testing 3
    $scope.testModel = { item1: true };
    

提交回复
热议问题