I have an issue with the comma separated with ng-repeat and ng-if.
I want to make the result as comma separated, but the last item is also include the comma.
My Expectation is : AAA, CCC, EEE
But the output is coming as : AAA, CCC, EEE,
The ng-repeat block is as below:
<div ng-repeat="provider in providersInfo">
<span ng-repeat="policy in policiesInfo | filter:{ProviderId : provider.ProviderId }:true">
<span ng-if="policy.HasChecked">{{ policy.PolicyName }}{{$last ? '' : ', '}}</span>
</span>
<!-- or -->
<span ng-repeat="policy in policiesInfo | filter:{ProviderId : provider.ProviderId }:true">
<span ng-if="policy.HasChecked">{{$index == 0 ? '' : ', '}}{{ policy.PolicyName }}</span>
</span>
</div>
Here, policiesInfo is join with lookup table, the output of JSON format is:
For each ProviderId it will contain 6 lookup records:
policiesInfo = [
{PolicyId : 1, PolicyName: 'AAA', ProviderId: 25, HasChecked: true },
{PolicyId : 2, PolicyName: 'BBB', ProviderId: 25, HasChecked: false },
{PolicyId : 3, PolicyName: 'CCC', ProviderId: 25, HasChecked: true },
{PolicyId : 4, PolicyName: 'DDD', ProviderId: 25, HasChecked: false },
{PolicyId : 5, PolicyName: 'EEE', ProviderId: 25, HasChecked: true },
{PolicyId : 6, PolicyName: 'FFF', ProviderId: 25, HasChecked: false }
]
Here $last is consider as PolicyId : 6 and $index is consider as PolicyId : 1