Use expression to create style class name

Description

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 {<!--from  ww  w  .  j  a v 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>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities