AngularJS Tutorial - Use expression to create style class name








The following code shows how to use expression to create style class name.

Example


<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<style>
.done-foo {<!-- ww w . j av  a 2 s  .c om-->
  text-decoration: line-through;
  color: grey;
}
.ng-binding {
    background: lightblue;
}
</style>
<script type='text/javascript'>
function TodoCtrl($scope) {
  $scope.foo = "foo";
  $scope.bar = "bar";
}
</script>
</head>
<body>
  <div ng-app>
  <div ng-controller="TodoCtrl">
    <span class="done-{{foo}}">{{bar}}</span>
    <span class="foo">{{bar}}</span>
  </div>
</div>
</body>
</html>

The code above is rendered as follows: