AngularJS Tutorial - ng-repeat loops through array from scope








The following code shows how to use ng-repeat loops through array from scope.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!--from   w  ww . j ava 2s.  co  m-->
<body>
  <div ng-app ng-controller="MainCtrl">
    <ul>
        <li ng-repeat="num in nums">{{num}}</li>
    </ul>
</div>
<script type='text/javascript'>
function MainCtrl($scope) {
    $scope.nums = ["1", "2"];
}
</script>
</body>
</html>

The code above is rendered as follows: