jeudi 5 mai 2016

How can i uncheck a checkbox in angular with an external function?

Basically i have a set of check boxes that when checked creates a set of tags, however i created a function that deletes the tag, the issue is i cant figure out how to uncheck the checkbox when deleting the tag.

<div class="" ng-repeat="(key, value) in filterTags"><div ng-click="changeTag(subproduct);">X</div></div>

<input type="checkbox" ng-model="active" ng-change="change(subproduct, active)">

Above is the html below are the functions

  $rootScope.change = function(subproduct, active){
        if (active){

            $rootScope.filterList.push(subproduct.subproduct_id);
            $rootScope.filterPush = "?subproducts[]="+$rootScope.filterList.join("&subproducts[]=");
            $rootScope.filterTags.push(subproduct.subproduct_name);
          }
        else{
            $rootScope.filterList.splice($rootScope.filterList.indexOf(subproduct), 1);
            $rootScope.filterPush = "?subproducts[]="+$rootScope.filterList.join("&subproducts[]=");
            $rootScope.filterTags.splice($rootScope.filterTags.indexOf(subproduct), 1);
          }
  };

  $rootScope.changeTag = function(subproduct, active){


        $rootScope.filterList.splice($rootScope.filterList.indexOf(subproduct), 1);
        $rootScope.filterPush = "?subproducts[]="+$rootScope.filterList.join("&subproducts[]=");
        $rootScope.filterTags.splice($rootScope.filterTags.indexOf(subproduct), 1);

  };




Aucun commentaire:

Enregistrer un commentaire