$index
does not increment within the ng-if
block.
<div ng-repeat="household in census.households track by $index">
<div ng-if="household.ask_for_tobacco">
<input id="tobacco_{{$index}}" type="checkbox" ng-model="member.smoker">
<label for="tobacco_{{$index}}"></label>
</div>
</div>
In the above block, I am using ng-repeat and ng-if
inside it. I am following the condition ng-if
and setting the element ID with $index
. The element ID is always being set to 0
, instead of incrementing to 1, 2, 3...
If the ng-if
is removed, it works without any issues. Have you faced a similar problem? If so, please share the solution.