Search code examples
angularjsformscheckboxangular-ngmodel

ng-model value not passed to the controller function


I am using ng-model to pass the form value to a controller function. But it is not passing correct values of the check boxes. Here is my plunker. Please help me out with this.

https://plnkr.co/edit/3gOuQwzt3SMNbAXplq0x?p=preview

My template is:

<div class="tab-pane fade " ng-repeat="(key, value) in all_user_wl_data" id="{{key}}" ng-class='{"in active":$first}'>
                        <div class="form-group">
                        <div class="row">
                            <div class="col-sm-6 col-md-6 col-lg-6" ng-repeat="(key1, value1)  in value.wl_dict">
                                <div class="checkbox checkbox-success">
                                <input id="{{key1}}" type="checkbox" name="valueis" class="form-control" ng-model="formData[key1]">
                                    <label for="{{key1}}">
                                        {{value1}}
                                </label>
                            </div>
                            </div>
                        </div>
                        </div>

         <div class="form-group">
                        <div class="row"><div class="col-lg-3 col-md-3 col-sm-3"> <label class="control-label">Group Name </label></div>
                        <div class="col-md-6 col-sm-6 col-lg-6"> <input type="text" name="regular" class="form-control" ng-model="formData.key2"></div></div><br>
                        <button type="button" class="btn btn-success" data-original-title="" title="" ng-click="createGroup(formData)">Save changes</button>

                </div>

Here when I print console.log(formData), it prints only the value of text box and doesn't prints checkbox value.


Solution

  • try this. in controller define $scope.formData = [];