You are pusing the item.visited
versus item
. You need to update your push
and indexOf
statements. (see the last part of my answer because filter
is better in your situation)
Change:
groupArrayNew.push(item.visited)
To
groupArrayNew.push(item)
$scope.getCountryGroups = function () {
var groupArrayNew = [];
angular.forEach($scope.countries, function (item, idx) {
if (item.Visited)
groupArrayNew.push(item)l
});
return groupArrayNew.sort();
}
You could also bypass the function and use the built in filter
:
<li ng-repeat="country in countries|filter:{visited:true}">{{country.name}}</li>
Sample plnkr that shows both: