AngularJS Tutorial - Click to change style








The following code shows how to click to change style.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<style type='text/css'>
.red {<!--   w  ww .j  av a 2s.  co  m-->
    color: red;
}
.blue {
    color: blue;
}
</style>
</head>
<body>
  <div ng-app>
    <button ng-class="myClass" 
            ng-click="myClass='red'" 
            ng-init="myClass='blue'">some text</button>
</div>
</body>
</html>

The code above is rendered as follows: