Harish Vishnoi Harish Vishnoi - 5 months ago 16
AngularJS Question

ng-class with dynamic values and condition not working on same div

This is not working working

<div id = "number_1" class="number" ng-click="selected='1'" ng-class="{active: selected=='1',firstactive: firstnumber=='1'}"><div class="number-text">1</div></div>
but if I apply ng-class with child div it works fine.

Answer

Works for me. Can you check this

var demo = angular.module('demo', []);
demo.controller('DemoCtrl', function($scope) {
  $scope.firstnumber = 1;
});
.active {
  color: green;
}
.firstactive {
  border: 1px solid red;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body ng-app="demo">
  <div ng-controller="DemoCtrl">
    <div id="number_1" class="number" ng-class="{active: selected=='1',firstactive: firstnumber=='1'}" ng-click="selected='1'">
      <div class="number-text">1</div>
    </div>
  </div>
</body>