Maria Jane Maria Jane - 11 months ago 55
AngularJS Question

ng-repeat without declaring array of object

<div ng-init="num_cover_photo:new Array(4)">
<div ng-repeat="photo in num_cover_photo">
<img ng-src="cover_"{{$index}} />

I know above code won't work, but that's my idea. I don't want to declare something like this

$scope.cover_photo = [{

because what I want is simple, able to use ng-repeat to build few block of markup. I'd google but many suggested I create a dumb array of object in controller. Any clue I can ng-init it on the fly?

Answer Source

If all you want to do is create a few blocks of markup, you could do a simple for loop in the ng-repeat

like so:

<div data-ng-repeat="i in [1,2,3,4,5]">
   do something

to create 5 blocks.