0

This is our controller code

              /**
        * @Summary: setProductInAlbum function, to create album
        * @param: index, productObj
        * @return: callback(response)
        * @Description:
        */ 
       $scope.allAlbums = [];
       $scope.sellerUserTypeKeyId = [];
       
       $scope.getAlbumsBySellerUserTypeKeyId = function() {
        $scope.sellerUserTypeKeyId = Number(AUTH.userTypeKeyId);
        var PRODUCT_DB_REF = firebase.database().ref('datastore/productsAlbum');
       
       PRODUCT_DB_REF.orderByChild("sellerUserTypeKeyId").equalTo($scope.sellerUserTypeKeyId)
       .on("value", function(snapshot) {
          var value = snapshot.val();
          if(value != null) {
          $scope.allAlbums = objToArray(value);
         }
        });
       }
              /**
        * @Summary: addProductKeyInAlbum function, to filter the connected user
        * @param: index, isChecked, productObj
        * @return: callback(response)
        * @Description:
        */
              
       $scope.getAlbumsBySellerUserTypeKeyId();
              $scope.selectedProductKey        = [];
       $scope.getSelectedProductObject  = [];
       
       $scope.addProductKeyInAlbum = function(index, isChecked, productObj) {
        $scope.productObj = productObj;
        if(isChecked) {
         //PUSH THE PRODUCT kEYID INO THE ARRAY AND PASS TO THE getProduct FUNCTION
         $scope.selectedProductKey.push($scope.productObj.keyId);
          var data = {
           keyId : $scope.selectedProductKey
          }
          //CALL THE getProduct FUNCTION FOR GET THE LIST OF THE SELCETD OBJECTS
          SellerDashboardService.getProduct(function(response) {
           if(response != null) {
            if (response.data.isSuccess) {
             $scope.getSelectedProductObject = response.data.UserProductList;
            }
           }
          }, data);
          //HERE WE WEILL BLANK THE ARRAY AFTER THE RESPONSE IS RECEIVED FROM THE SERVICE
        } else {
         //SPLICE THE PRODUCT kEYID FROM THE ARRAY 
         $scope.selectedProductKey.splice(index, 1);
         console.log($scope.selectedProductKey);
        }
       }
              
              

I have an 2 array if the id will be match checkbox will be checked but if id will be not match checkbox is uncheck but in my condition both the checkbox will be checked

<div id="removeSelectedProductKey" class="checkbox albumSection w3-margin-top-10" ng-repeat="productObject in getSelectedProductObject">
  <div class="w3-margin-top-10" ng-repeat="albumList in allAlbums">
    <div>
      <input type="checkbox" ng-checked="productObject.keyId == albumList.productKey" ng-click="removeSelectedProductKey($event, $index)" />
    </div>
    <div>
      <input type="checkbox" ng-checked="productObject.keyId != albumList.productKey" />
    </div>
  </div>
  <label>
  </label>
  <br>
</div>

<div id="removeSelectedProductKey" class="checkbox albumSection w3-margin-top-10" ng-repeat="productObject in getSelectedProductObject">
  <div class="w3-margin-top-10" ng-repeat="albumList in allAlbums">
    <div>
      <input type="checkbox" ng-checked="productObject.keyId == albumList.productKey" ng-click="removeSelectedProductKey($event, $index)" />
    </div>
    <div>
      <input type="checkbox" ng-checked="productObject.keyId != albumList.productKey" />
    </div>
  </div>
  <label>
  </label>
  <br>
</div>

how to resolve this issue?

Kapil Soni
  • 1,003
  • 2
  • 15
  • 37

1 Answers1

0

Rather using ng-if or ng-disabled, you can make use of ng-checked, like this:

<div>
  <input type="checkbox" ng-checked="1 == 2" />
</div>
<div>
  <input type="checkbox" ng-checked="1 == 1" />
</div>

Check here.

Another thing is whatever you write in checked="" it will always be treated as true. For reference, see this answer.

Also by using ng-checked you don't have to write the same checkbox code two times, so it will be checked if the condition is true and unchecked if the condition is false.

Update

Plunker

Aayushi Jain
  • 2,861
  • 2
  • 29
  • 36