user3340037
user3340037

Reputation: 731

Using ng-repeat twice in view using same controller

I'm using one controller for a view that looks like this

<div>
<div ng-repeat="blah in blah1">
</div>
<div ng-repeat="blah in blah2">
</div>
</div>

The issue is that the second time ng-repeat is used, it seems to duplicate what was seen in the first repeat. I have confirmed that blah1 is in fact different from blah2. I'm not sure as to why the second ng-repeat goes through items in blah1.

Any clues?

Thanks!

Upvotes: 0

Views: 1554

Answers (3)

jfplataroti
jfplataroti

Reputation: 661

maybe the ng-repeat for blah2 is included inside the ng-repeat of blah1, so it repeats blah1 content everytime blah2 is iterated.

otherwise should work fine

<div ng-app='bla'>

<div  ng-controller='ctrl'>
    <div ng-repeat="blah in blah1">
        <span>{{blah}}</span>
    </div>
    <hr/>
    <div ng-repeat="blah in blah2">
        <span>{{blah}}</span>
    </div>
</div>

</div>

<script>
    angular.module('bla', [])
.controller('ctrl', ctrl);

function ctrl($scope){

    $scope.blah1 = [1,2,3,4,5,6,7,8,9];

    $scope.blah2 = [21,22,23,24,25,26,27,28,29]

}
</script>

https://jsfiddle.net/hsdcpk2x/1/

Upvotes: 3

Sander
Sander

Reputation: 103

ng-repeat goes just over all the items in blah1 and blah2. If the second ng-repeat duplicates blah1 then they are in fact the same. You should post more code so we can get to the actual issue.

Upvotes: 1

aakash mon
aakash mon

Reputation: 15

use ng-repeat-start and ng-repeat-end
hope it would solve your issue

Upvotes: -1

Related Questions