• Introduction:

     

    In this article we will explain how to use ng- repeat  in AngularJS or what is ng- repeat  in        AngularJS or how to bind a table using ng- repeat  in AngularJS with example.


    Description:

     

    The AngularJS ng- repeat directive use for making a HTML table, displaying one table row for each items of an array or an object.


Example ng-repeat: 

@{
    ViewBag.Title = "Home Page";
}
 
<script src="~/Scripts/jquery-3.1.1.js"></script>
<script src="~/Scripts/angular.js"></script>
 
<div ng-app="mainApp" ng-controller="MyController">
         
    <table border="0">
            <tr>
                <td colspan="3"><h2>AngularJS ng-repeat</h2></td>
            </tr>
        <tr ng-repeat="x in data.records">
            <td>{{x.id}}</td>
            <td>
                {{x.name}}
            </td>
            <td>{{x.email}}</td>
        </tr>
           
        </table>
  
</div>
 
<script>
    var mainApp = angular.module("mainApp", []);
    mainApp.controller('MyController', function ($scope) {
        $scope.data = {
        records:[{ id: '1', name: 'Rajeev',email:'rajeev@@adityapoint.in' },
                 { id: '2', name: 'Tarun' ,email:'tarun@@adityapoint.in'},
                 { id: '3', name: 'mayank',email:'mayank@@adityapoint.in' },
                 { id: '4', name: 'Sohel',email:'sohel@@adityapoint.in' },
                 { id: '5', name: 'karan', email: 'karan@@adityapoint.in' }]
    }
            
    });
</script>
<style>
    table {
        width:500px;
        margin:0 auto;
    }
     table, th, td {
        border: 1px solid grey;
        border-collapse: collapse;
        padding: 5px;
    }
 
        table tr:nth-child(odd) {
            background-color: #ccc;
        }
 
        table tr:nth-child(even) {
            background-color: #ffffff;
        }
</style>
 


RESULT:


what is ng-repeat in AngularJS


  •        I hope this article will help to you.


 

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

you may also like