mardi 3 novembre 2015

How to pass check box values in AngularJS using ng-model in conjunction with ng-repeat

I have a page which offers users the ability to search for articles by entering a search term and filter the results if required.

The filters initially contained multiple select box with values been fetched from ajax call and the selected values been sent back using ng-model. It was working fine.

Now the requirement is to convert multiple select box into checkboxes and I have managed to create the checkbox.

I am facing issues when users enter a search query and selects one of the checkboxes, I am not able to get the selected checkbox value in app.js to filter the results.

<div class="col-lg-3">
    <h3 class="m0 pb-lg">Filters</h3>
    <div class="form-group mb-xl">
         <form method="get" ng-controller="SearchController as form" class="form-horizontal">
            <label class="control-label mb">By Type of Study</label><br><label class="checkbox-inline c-checkbox" ng-repeat="s in form.typeOfStudies">
            <input type="checkbox" ng-model="search.typeOfStudy" ng-true-value="'YES'" ng-false-value="'NO'">
                <span class="fa fa-check"></span>{{s}}</input>
            </label>
            <br>
        </form>
    </div>
</div>
</div>

The app.js contains:

 $scope.getById = function (id) {
           if (id.typeOfStudy){
            $.each(id.typeOfStudy, function() {
                    if (count < id.typeOfStudy.length) {
                        count++;
                        qTypeOfStudy += "'" + this + "',";
                    }
                    else if (count == id.typeOfStudy.length) {
                        qTypeOfStudy += "'" + this + "'";
                    }
            })
        }
  }

getById is been passed on form submission of main text in the search bar on the page.




Aucun commentaire:

Enregistrer un commentaire