AngularJS ng-repeat: filter: $ variable does not work well when you use 'true' for a strict comparison

advertisements

I receive a JSON file of Stores, with id, name, among other data. I have a view called List, and other called Detail.

In List, I list all the JSON with ng-repeat. In Detail, I have the 'same' list, but ng-repeat I use filter by id like:

<div class="item" ng-repeat="item in spots | filter:{id: idSpot}">
{{item.id}} - {{item.name}}
...

But the problem I've encountered is that when I filter the business id: 3, it shows, all the businesses with a number 3 (3, 30, 73, 33, ...).

I've found also that the true element, forces to make the comparison strictly to the received value:

<div class="item" ng-repeat="item in spots | filter:{id: idSpot}:true">

Works perfect, when I write "filter:{id: 7}:true", equal to seven.

But it does NOT work when I compare it like it is written, {id: idSpot}

$scope.idSpot is properly set at the Controller, and I know it works, because it showed all the three's (3, 33, 73, 39,...) before. I can console.log($scope.idSpot) and confirm it receives an integer.

But the variable doesn't work with 'true'.

How could I polish that??

Thank you!


Alright, as I had a lot of time to think, I've found a patch to carry on from.

As this code:

<div class="item" ng-repeat="item in spots | filter:{id: idSpot}">
{{item.id}} - {{item.name}}
</div>

When receive a one-digit number, like 3; it printed all numbes with a 3 (13, 31, 33,34,...), I will add the ng-if clause, to take $index == 0, that is the first lowest result returned. The #3.

<div ng-repeat="item in spots | filter:{id: idSpot}" ng-if="$index == 0">

Didn't correct the Filter though. Thank you for reading.