2016-10-07 3 views
0

ng-repeat에서 생성 된 테이블이 있습니다. 각 행에는 확인란이 있습니다. 나는 그들의 배경 색깔을 바꾸기 위하여 검사되는 줄을 원한다. ng-class를 사용하여 시도했지만 도움이되지 않았습니다. 하나의 체크 박스를 선택하자마자 모든 행이 백그라운드로 바뀌 었습니다. 실수가 무엇인지 이해하지만 해결 방법을 모릅니다.angularjs에서 선택되지 않은 행의 배경색을 변경하십시오.

이이 내가 잘 작동하는 다른 목적에 대해 "수를"필요 내 컨트롤러

$scope.countChecked = function(index){ 
     var count = 0; 
     angular.forEach($scope.jobs, function(job){ 
      if (job.checked) { 
       count++; 
       $scope.myclass='selected'; 

      } 
     }); 
    return count; 
    } 

내 테이블

<table > 
     <tr> 
     <th>Select</th> 
     <th>Job List</th> 
     <th>Next Firing</th> 
     </tr> 
     <tr ng-repeat="x in jobs" ng-class-odd="'odd'" ng-class-even="'even'" ng-class="myclass"> 
      <td style="width: 247px; "><input type="checkbox" ng-model="x.checked" ng-click=countChecked($index)></td> 
      <td style="width: 247px; ">{{ x.Name }}</td> 
      <td style="width: 247px; ">{{ x.ID }}</td> 
     </tr> 
     </table> 

입니다. job가과 같이 선택한 경우

는 CSS를

.selected{ 
    background-color: #DEB887; 

    } 

답변

3

당신은 그것을 특정 클래스를 제공하기 위해 ngClass 지시어를 사용할 수 있습니다에게 선택 :

<ANY ... ng-class="{ 'selected': x.checked }"> 
    ... 
</ANY> 
+0

그래, 헤이 그것은 worked..thnks 톤. 그래서 나 바보. 나는 체크 박스 모델이 나중에 정의되어서 동작하지 않을 것이라고 생각했다. – Tedsville

+0

글쎄, 나중에 정의되었지만, anglejs는 템플릿을 정의 할 때 실제 범위 상태를 반영하기 위해 템플릿을 다시 그리기한다. –