2个孩子的父ng-class ng-click angularjs

时间:2016-03-01 16:10:06

标签: javascript angularjs angularjs-ng-click ng-class

我尝试使用不同的子ng-click更改父类名称 这是代码:

<div class="item"
             ng-class="{'_first': isFirst, '_second': isSecond}"
             ng-repeat="item in currentCtrl.currentData">
 <div class="btn-container">
                <button class="btn"
                        ng-click="isFirst = !isFirst">first</button>
            </div>
            <div class="btn-container">
                <button class="btn"
                        ng-click="isSecond = !isSecond">second</button>
            </div>
</div>

它只是第一次工作 我错过了什么?

编辑: 发现麻烦,代码是正确的

1 个答案:

答案 0 :(得分:1)

你喜欢这个吗?

&#13;
&#13;
var app = angular.module("app",[]);
app.controller("ctrl", function($scope){
  
  $scope.items = [1,2,3,4];
  $scope.isSecond = true;
  $scope.isFirst = false;
 
    
   
  })
&#13;
._first{
  color:red;
  }

._second{
 color:blue;
  }
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="app" ng-controller="ctrl">

       <div class="item" ng-class="isFirst== true ? '_first' : '_second'"
         ng-repeat="item in items">
         <p> this is a test</p>
             <div class="btn-container">
                <button class="btn"
                        ng-click="isFirst= !isFirst">first</button>
            </div>
            <div class="btn-container">
                <button class="btn"
                        ng-click="isFirst = !isFirst">second</button>
            </div>
        </div>
  
 </div>
&#13;
&#13;
&#13;