Angular Repeat test

by Luiz Silva

HTML

<input type="text" ng-model="numeroRepeticoes" ng-change="update()"/>
<br/>
Itens:
<div ng-repeat="item in items">Item {{ item }} ({{ $index }})</div>

JavaScript

var loopApp = angular.module('loopApp', []);

loopApp.controller('LoopCtrl', function ($scope) {
    $scope.update = function() {
        $scope.items = [];
        var total = parseInt($scope.numeroRepeticoes);
        for (var i = 0; i < total; i++) {
            $scope.items.push(i + 1);
        }
    };
});