Search code examples
javascriptangularjsangular-ngmodelangularjs-ng-clickng-class

ng-class applied on pageload, expression is untrue


I'm trying to apply a class to the parent tr of a td that holds a checkbox element. The code works fine, except that the first time the page the loads, the tr already has the class applied, even though the checkbox is unchecked. If i click on the tr element once, the style is removed, and then the element functions as expected. Why is the class getting picked up on page load? The code:

<tr ng-click="isChecked = !isChecked" ng-class="{'hovered': isChecked}">
          <td class=""><input type="checkbox" ng-model="isChecked" /></td>
          <td >Accountability</td>
</tr>

Solution

  • Can you show the controller code as well. It seem to be working when I created this JSBin for the same scenario: https://jsbin.com/saqube/edit?html,css,js,output

    I think there might be some issue in your controller or angularjs version