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

后端 未结 6 837
别跟我提以往
别跟我提以往 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:12

    You don't need ng-checked when you use ng-model. If you're performing CRUD on your HTML Form, just create a model for CREATE mode that is consistent with your EDIT mode during the data-binding:

    CREATE Mode: Model with default values only

    $scope.dataModel = {
       isItemSelected: true,
       isApproved: true,
       somethingElse: "Your default value"
    }
    

    EDIT Mode: Model from database

    $scope.dataModel = getFromDatabaseWithSameStructure()
    

    Then whether EDIT or CREATE mode, you can consistently make use of your ng-model to sync with your database.

提交回复
热议问题