My goal is to use a custom filter in Angular to filter an array.
Essentially, I have a binding set up like this:
{{ myData.winners | getWinnerString }}
, which returns an array of items with a length ranging from 1 to 4. If the array consists of more than one item, I want to display a specific string like "Two way tie," "Three way tie," and so on based on the length of the array. If there's only one item, I just want to display the winner as it is. Here is what I currently have:
.filter('getWinnerString', function() {
return function(array) {
console.log(array);
return array;
}
});
Upon running this code, the array gets looped through twice and logged twice. Any thoughts on why this might be happening? Additionally, any guidance on how to correctly implement this function to display the appropriate string would be highly valued, as all my previous attempts have been unsuccessful.