简体   繁体   中英

how can i selected a button to select a size for a shopping cart app using angularjs

this is my code in controller

$scope.status = false;
  $scope.clickOn = function () {

    if ($scope.status == false) {
      this.status = true;
    } else {
      this.status=false;
   }
  };

here is my html field

<div class="sizes">
                    <button ng-repeat="size in $ctrl.cart.sizes" class="button-size"
                        ng-class="{true:'active',false:'deactive'}[status]" ng-click="clickOn()">
                        <span>{{size}} UK</span>
                    </button>

                </div>

when I click on the button the class active have been used but when I click again the class deactive never work there are any solution for this ?? thanks you guys so much

You may want to add "track by $index" and activate/deactivate the button based on the $index. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM