how to maintain checkbox state after http call is over in angular js

how to maintain check box state when checkbox is clicked after server response comes back.
when user clicks YES checkbox,it calls trackFilter function and in turn calls http service calls but checked state is disappearing once response comes back.

var xx = angular.module('xx', '');

                           var req = {
                                        "search": {
                                            "field": "xxx",
                                            "text": "zzz"
                                        },
                                        "filters": [] 
                                };
								
								 xx.factory('productFactory', function($http,$q){
    
							var defer = $q.defer();

							$http.post('prodsearch',req).then(function(data){
									defer.resolve(data);
							  });


                    return {
                            getResponse : function () {
                                return defer.promise; 
                            },
							
                            searchFilter:function(val,facetname){
                                    var query={
                                            "facets": {
                                                 "value1": val
                                            }
											"facets1": {
                                                 "value2": val
                                            }
                                      };

                               req.filters.push(query[facetname]);
                               var deferred = $q.defer();
                                
                               $http.post('prodsearch',req).then(function (response) {
                                      deferred.resolve(response);
                                });
                                
                                return  deferred.promise; 
                            }
              }      

         }).controller('productsCtrl', function($scope, productFactory) {

            $scope.productList = {};
		
                //This will be called when the page loads
                var promise= productFactory.getResponse();
					promise.then(function(resp)
					{
						$scope.productList = resp.data;
	                });

		  //This will be called when the trackFilter called
            $scope.trackFilter = function (val,name) {
  
                var promise = productFactory.searchFilter(val,name);
                 promise.then(function(resp)
                    {
                        $scope.productList = resp.data;
				    });

            };//end of trackFilter
			
		



});//end of productsCtrl

html
******
<html ng-app="xx">
<div id="leftNav" ng-controller="productsCtrl">
                      
                        <div>
                            <div>

      
<h2>Filter</h2>
<ul>
     
<li ng-repeat="x in productList.productAggs">
       <input type="checkbox" ng-click="trackFilter(x.flag,'facets')">
            &nbsp;<span>Yes</span>
           
         
      </li>
	  <li ng-repeat="x in productList.productAggs">
       <input type="checkbox" ng-click="trackFilter(x.flag,'facets')">
            &nbsp;<span >No</span>
          
         
      </li>


</ul>


    </div>
</div>
</div>
</html>
response json
******************
var json= {"productAggs": [
            {
                "count": 2,
                "flag": true
            },
            {
                "docCount": 0,
                "flag": false
            }
			]
			}

Open in new window

LVL 20
chaitu chaituAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BigRatCommented:
The <input> checkbox has no model. I suspect it might be x.flag. In fact I don't understand why productList.productAggs is being rendered twice? It would be more sensible to render it once with two boxes.

If you are trying to facet a product list with product types (menswear, womenswear, childswear for example) you might try using an open source faceting directive/module.

Elastic Search gives a good example of how the data is to be presented
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-facets.html
and how it gets faceteted :-
http://www.fullscale.co/blog/2013/03/07/getting_started_with_elasticsearch_and-AngularJS_faceting.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Angular

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.