How to bind dynamic Check boxes value using ng-model?

后端 未结 3 785
生来不讨喜
生来不讨喜 2021-01-24 09:07

I want to put the values of dynamic checkboxes (not boolean true and false) in the form of array using \'ng-model\' in a similar way as is done using \'name\' attribute. This ar

3条回答
  •  借酒劲吻你
    2021-01-24 09:24

    According to your example listed there, you have bound your ng-model to the expression operations, however you need to be binding it to the individual iterator operation (from) ng-repeat="operation in operations_publish".

    You can then set that data in your dataLog object:

    var dataObj = {
        "operationType" : $scope.operationType,
        "conceptModelID" : $scope.conceptID,
        "requestor" : $scope.requestor,
        "status" : "new",
        "requestDateTime" : null,
        "lastExecutedDateTime" : null,
        "completedDateTime" : null,
        "instructions" : $scope.operations_publish
    };
    

    Data binding by default in angular are multi-directional therefore:

    1. operations_publish => bound to row via iterator operation
    2. operation => bound to checkbox value via ng-model
    3. When the value of the checkbox changes, you change the variable it was bound to, and the collection that variable iterated from.

提交回复
热议问题