Kreamy Kichen

Adding and removing classes in angularJs using ng-click

By April 4, 2016 angular No Comments

Demo: http://jsfiddle.net/geonunez/pWG2S/

var app = angular.module("ap",[]);

app.controller("con",function($scope){
  $scope.class = "red";
  $scope.changeClass = function(){
    if ($scope.class === "red")
      $scope.class = "blue";
    else
      $scope.class = "red";
  };
});
.red{
  color:red;
}

.blue{
  color:blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="ap" ng-controller="con">
  <div ng-class="class">{{class}}</div>
  <button ng-click="changeClass()">Change Class</button>    
</body>

Leave a Reply

Contact Us

Pathanamthitta Office
Palavila House Near Karikkineth Adoor PIN:689693

Trivandrum
Benson Record Inn Studio Palayam PIN:695033