用 angularjs 修改 css class

Modifying css class with angularjs

我正在尝试更改输入单选组中所选按钮的 class。每个按钮代表一个座位,然后显示选中的总数。

   $scope.calculateChecked = function() {
      var count = 0;
      
      angular.forEach($scope.data, function(value) {
        if(value.checked)
          count++;
      });
      
      return count;
   };

这是我的 plunker 示例: http://plnkr.co/edit/wKzcz6TbYmfbL5mW?open=lib%2Fscript.js&deferRun=1

What I'm trying to accomplished is that when a particular seat selected (ie: seat 4), then all the previous seat (1,2,3) will be selected automatically, and then calculated as 4 seats price , like so

我知道我使用的是过时的版本,但我仍在学习基础知识。

提前感谢所有帮助和建议,非常感谢:)

这是我的 Demo 和 Plunker。

在您看来: 而不是 show 属性 使用模型的 user.checked 属性,所以您不必同步两个值。

<label style="width:100px;padding: 13px;border-radius: 5px;background: dimgray;
       text-align: center;color: white;box-shadow: 0px 0px 17px -4px rgba(140,140,140,1);" 
       ng-class="{checked: user.checked}">
<input type="checkbox" style="display:none" value="1" name="options" 
       ng-model="user.checked" ng-click="userClick(user)"/>
<i class="fas fa-couch h2 px-2"></i><br />
${{price}}
{{ x }}
</label>

控制器:添加此功能

$scope.userClick = function(user) {
    if(user.checked) {
       var i = 0;       
       while($scope.data[i].name != user.name)
       {
          $scope.data[i].checked = true;
          i++;
       };
    }
};