Reputation: 14142
I have a $scope variable epochs
that loops through an array containing 3 items -
<div class="epoch" ng-repeat="epoch in epochs" ng-init="epochIndex = $index">
<div class="epoch-time">
<span class="epoch-header">{{epoch[epochIndex].epoch}} {{ epochIndex }}</span>
</div>
Expected result : See the following divs in the template
<span class="epoch-header">Today 0</span>
<span class="epoch-header">Tommorow 1</span>
<span class="epoch-header">Thu, 11 Jan 2</span>
Actual result :
<span class="epoch-header">Today 0</span>
<span class="epoch-header">1</span>
<span class="epoch-header">2</span>
I can view the variable from the console and when I run the scope variable with each numerical key I can see the expected values - it just doesn't pass through to my template for the latter spans??
Can anyone suggest what is incorrect?
Upvotes: 1
Views: 39
Reputation: 2332
You are doing it wrong , try this
<div class="epoch" ng-repeat="epoch in epochs" ng-init="epochIndex = $index">
<div class="epoch-time">
<span class="epoch-header">{{epoch}} {{epochIndex}}</span>
</div>
</div>
Upvotes: 0
Reputation: 222720
You mean?
<div class="epoch" ng-repeat="epoch in epochs">
<div class="epoch-time">
<span class="epoch-header">{{epoch}} {{ $index }}</span>
</div>
Upvotes: 0
Reputation: 538
You can do directly this:
<div class="epoch" ng-repeat="epoch in epochs">
<div class="epoch-time">
<span class="epoch-header">{{epoch}} {{$index}}</span>
</div>
</div>
Upvotes: 1