title: Angular.js inifinite digest loop with nested ng-repeat and filter
body: <p>I've created a custom filter in angular js which groups my elements by type and <strong>searches for Multiple search-terms in all attributes of devices</strong>.</p>
  
  <pre><code>angular.module('abc').filter('searchFor', function(){
  return function(array, searchString){
  var arr =[]
    if(!searchString.length){
      return array;
    }
    var result = [];
    for(var i=0;i&lt;array.length;i++){                    //put all 
    devices of all device Groups into arr
    var temp = array[i].devices
      for(var j=0;j&lt;temp.length;j++){
        arr.push(temp[j])
      }
    }
    // search in tags of arr individual searchString
    for(var i=0; i&lt;searchString.length;i++){
      searchString[i] = searchString[i].toLowerCase()
      var res = []
      for(var k in arr){
      //there are some tags in device data object so I am searching in the same
        var tags = arr[k].tags
        tags.push(arr[k].ID)
        tags.push(arr[k].Name)
        tags.push(arr[k].Type)
  
        for(var j in tags){
          if(tags[j].toLowerCase().indexOf(searchString[i]) !== -1){      // if tags matches with searchString push it in res
            res.push(arr[k]);
            break;      // push one device only once
          }
        }
        result[i] = res                     //here i refers to search-term number ie. search-term i's result is saved in result[i]
      }
    }
  if (result.length &gt; 1) {
    // there are more than 1 chips to search
      result.sort(function(a,b) {                     // sort result array acc to its element's length
      return a.length - b.length
    })
    // find intersection between every 2 consecutive arrays in result
    // and store that intersection at i+1 index of result
    for(i=0;i&lt;result.length-1;i++){
      var a = result[i]
      var b = result[i+1]
      var common = []
      for (var j = 0; j &lt; a.length; j++) {
        for (var k = 0; k &lt; b.length; k++) {
          if (a[j].ID == b[k].ID) {
            common.push(b[k])
            break;
          }
        }
      }
      result[i+1] = common
    }
    // finally store the intersection of all arrays of result in resultFinal
    resultFinal = common
  }else {
    //result of only 1 search-term 
    resultFinal = result[0]
  }
  /* Finally resultFinal contains the devices satisfying the search 
  criteria
   Before returning back group all the devices according to their 
  device types in deviceGroups(data Structure is as mentioned in demo 
  output) */
    return deviceGroups
  }
  })
  </code></pre>
  
  <p>What it does:
  The input (device_data) is an array of devices. Every task has a 'type' parameter defined. I need to separate these devices by type. Each Device Type holds its respective devices array.
   It works, but ends up in an infinite digest loop.</p>
  
  <p>Examples of input and output:</p>
  
  <pre><code>$scope.device_data = [
      {name: 'D_1', type: 'wmeter'},
      {name: 'D_2', type: 'fmeter'},
      {name: 'D_3', type: 'smeter'},
      {name: 'D_4', type: 'fmeter'}
  ]
  </code></pre>
  
  <p>The output has to be grouped like this:</p>
  
  <pre><code>[
      'watermeter': [
          {name: 'D_1'}
      ],
      'flowmeter': [
          {name: 'D_2'},
          {name: 'D_8'}
      ],
      'solar': [
          {name: 'D_3'}
      ]
  ]
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;div ng-repeat="group in deviceGroups | searchFor: searchString"&gt;
  
      &lt;h2&gt;{{group.type.toUpperCase()}}&lt;/h2&gt;
  
       &lt;div ng-repeat="device in group.devices"&gt;
           &lt;p&gt;{{device.name}}&lt;/p&gt;
       &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>