Aro Tonoyan Aro Tonoyan -4 years ago 96
AngularJS Question

Inspect all items on ng-repeat

If the first prematchGame has 1 and 2 value ,after that add header , but in this case i have some issue ,,,first element hasn't 1 and 2 value , but 3th and 4th has it . (see on image)

How can i check , that if 1 element has 1 and 2 value in ng-repeat then add in header .

My code
(and sorry for bad english)

<li ng-show="groupGames[0]" title="1">1</li>
<li ng-show="groupGames[0]" title="2">2</li>

<div ng-repeat="prematchGame in groupGames track by">

enter image description here

Answer Source

define a function to filter for the target item.

$scope.hasItemWithProperty = function (key) {
    return $scope.groupGames.some(prematchGame => {

use the function in the template like this

  <li ng-show="hasItemWithProperty('P1')" title="1">1</li>
  <li ng-show="hasItemWithProperty('P2')" title="2">2</li>

this is a plunker of the above.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download