How can I reference $odd
or $even
by variable in ng-repeat
?
I am trying to do this:
<ng-repeat="item in items" ng-if="$odd">these are odd{{item}}</div>
<ng-repeat="item in items" ng-if="$even">these are even {{item}}</div>
By doing this:
<div ng-repeat="side in sides">
<div ng-include='template'></div>
</div>
//template
<ng-repeat="item in items" ng-if="side">these are {{side}} {{item}}</div>
//in the controller
$scope.sides = ['$odd','$even']
{{side}}
results in $odd
and $even
text on the document where expected, but all the {{item}}
are coming through.
I've tried ng-if="side"
, ng-if=side
, ng-if={{side}}
, ng-if=" 'side' "
.
I'm sure this is just my rookie ignorance at play and its staring me right in the face.
Edit:::
Sorry I wasn't clear. Assigning $odd and $even was simple enough if I wanted to write out the whole layout longhand, which I relented and did for now. What I would like to do, however, is use ng-include to template the reused portions of the layout as much as possible. A very simplified version of my layout looks something like this:
What I would like to do is turn something like this:
<div class="outer-column1">
<div class="innercolumnA">
<div class="thumbnail" ng-repeat"thumbnail in thumbnail" ng-if"$even"></div>
</div>
<div class="innercolumnB">
<div class="thumbnail" ng-repeat"thumbnail in thumbnail" ng-if"$odd"></div>
</div>
</div>
<div class="outer-column2">
<div class="innercolumnA">
<div class="thumbnail" ng-repeat"thumbnail in thumbnail" ng-if"$even"></div>
</div>
<div class="innercolumnB">
<div class="thumbnail" ng-repeat"thumbnail in thumbnail" ng-if"$odd"></div>
</div>
</div>
into something like this:
<div ng-include="outer-column" ng-repeat="outercolumn in outercolumns"></div>
//template outer-column
<div class="outer-column">
<div ng-include="inner-column" ng-init="innercolumns = [$odd,$even] " ng-repeat="innercolumn in innercolumns"></div>
</div>
//template inner-column
<div class="innercolumn" ng>
<div ng-include="'thumbnail'" ng-repeat"thumbnail in thumbnail" ng-if"innercolumn"></div>
</div>
//template thumbnail
<div class="thumbnail"></div>
The question is: how can I reference the $odd and $even variables for ng-if indirectly? for example, I tried an ng-init="sides = [$odd,$even]" and passed that in the ng-repeat for the innercolumn template
and put ng-if="side"
into the template, but no go.
I also thought about passing a function like ng-if="whichSide(side)" That would return $odd or $even, but it seems like the $odd and $even variables are not defined on the $scope object...
But that's the spirit of what I'm trying to understand regarding the $odd and $even variables and indirectly referencing them.... Hope that makes sense. The project is working just fine, it's just annoying to make changes to 10 lines of code whenever I make an update vs. 3 lines of templated layout. Thanks!