AngularJs ng-repeat with Arrays


The ng-repeat is directive that is use to iterate the array data objects in the DOM elements as given below.

//The AngularJS code sample
var app = angular.module('myApp', []);
app.controller('myRepeatCtrl', function($scope) {
      $scope.employee = [{
                Id: 1,
                name: 'EMP1'
            }, {
                Id: 2,
                name: 'EMP2'
            } ,{
                Id: 3,
                name: 'EMP3'
   }];
});

//The HTML code sample
<div ng-app="myApp">
    <div ng-controller="myRepeatCtrl">
        <div>ID   Name </div>
        <div ng-repeat="emp  in employee">
            <div >
                <div>{{emp.Id}} || {{emp.name}}</div>
            </div>
        </div>
    </div>
</ div >

//The Full live code sample(HTML + AngularJs) as given below
<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
    <script>
        var app = angular.module('myApp', []);
        app.controller('myRepeatCtrl', function($scope) {
             $scope.employee = [{
                Id: 1,
                name: 'EMP1'
            }, {
                Id: 2,
                name: 'EMP2'
            } ,{
                Id: 3,
                name: 'EMP3'
            }];

        });
    </script>
</head>
<body ng-app="myApp">
    <div ng-controller="myRepeatCtrl">
        <div>ID   Name </div>
        <div ng-repeat="emp in employee">
            <div>
                <div>{{emp.Id}}   {{emp.name}}</div>
            </div>
        </div>
    </div>
</body>
</html>
The live output as,

About Blogger

ANIL SINGH

Hey! I am Anil Singh. I am Active Blogger, Writer and Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
http://www.code-sample.com
http://www.code-sample.xyz

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment

SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book