Reputation: 2719
I don't think this question fits in the context of angular.Am having an array of integers var myArray=[1,2,3,4,5]
.Is it possible to do a ng-repeat and display the integers on myArray
Upvotes: 0
Views: 3617
Reputation: 114
You can also code as below:
<div ng-repeat="i in [1, 2, 3, 4, 5]">
{{$index + 1}}
</div>
Upvotes: 1
Reputation: 136154
First thing you need place that variable inside scope variable then only you could use it on html.
Controller
angular.module('app', [])
.controller('Ctrl', function Ctrl($scope) {
$scope.myArray = [1, 2, 3, 4, 5];
});
Markup
<div ng-app="app" ng-controller="Ctrl">
<ul>
<li ng-repeat="item in myArray">{{item}}</li>
</ul>
</div>
Upvotes: 1
Reputation: 691765
Yes:
<div ng-repeat="i in myArray track by $index">
{{ i }}
</div>
The relevant documentation, BTW, shows an example doing what you want.
And of course, the array must be in the $scope, not just declared as a local variable of your controller.
Upvotes: 3