ng-repeat to create table cells

Description

The following code shows how to use ng-repeat to create table cells.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<style type='text/css'>
tr:nth-child(odd) {<!--from  ww w . j  a  v a 2  s.  c o  m-->
    background-color : green;
}
tr:nth-child(even) {
    background-color : blue;
}
</style>
</head>
<body ng-app="myApp">
  <div ng-controller="MyCtrl">
  <table>
    <tr ng-repeat="item in items">
        <td>{{item}}</td>
    </tr>
  </table>
</div>
<script type='text/javascript'>
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
    $scope.items = ['foo', 'bar', 'foobar'];
}
</script>
</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities