title: $rootScope:infdig error caused by filter
body: <p>I am using ng-repeat to print a list of items and using a custom filter to do some operations.The HTML code is</p>
  
  <pre><code>&lt;ul class="list"&gt;
        &lt;li class="item item-text-wrap" ng-repeat="item in searchJson | customFilter:search.value"&gt;
        &lt;div class="row row-center row-height"&gt;
        &lt;font class="text_color"&gt;
          &lt;span ng-bind-html="highlight(item.name, search.value)"&gt;&lt;/span&gt;
        &lt;/font&gt;
        &lt;/div&gt;
        &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>The CustomFliter is</p>
  
  <pre><code>.filter('customFilter', function () {
   return function (arr,searchString) {
   var names = [];
   var ans = [];
   var item = {};
  
  
   if(!searchString){
          return arr;
      }
   searchString = searchString.toLowerCase();
      angular.forEach(arr, function(item){
      if(item.name.toLowerCase().indexOf(searchString) !== -1){
        names.push(item);
      }
     else{ 
      if(item.metadata.toLowerCase().indexOf(searchString) !== -1){
          ans.push(item);
        }
      }
      });
  //want to add a header for names
  if(names.length!=0)
  {
    item['name']='&lt;font color="black"&gt;&lt;b&gt;Most relevant results&lt;/b&lt;/font&gt;'
    names.splice(0,0,angular.copy(item));
  
  }
  //want to add a header for questions
  if(ans.length!=0)
   {
     item['name']='&lt;font color="black"&gt;&lt;b&gt; Other relevant results&lt;/b&gt;&lt;/font&gt;'
     ans.splice(0,0,angular.copy(item));
   }
  return names.concat(ans);
  };
  })
  </code></pre>
  
  <p>Everything works fine without the splice condition(ng-repeat).In the presence of splice am getting $rootScope.infdig error.I went through these links <a href="https://docs.angularjs.org/error/" rel="nofollow">https://docs.angularjs.org/error/</a>$rootScope/infdig
  <a href="https://docs.angularjs.org/api/ng/provider/" rel="nofollow">https://docs.angularjs.org/api/ng/provider/</a>$rootScopeProvider</p>
  
  <p>It is very clear that we cannot add items during digest cycle.Is there a way to add a header dynamically.Can anyone help on this issue.</p>
  
  <p>I tried using collection-repeat and it is working fine but the problem is, If I navigate to the second page and come to this page again nothing is visible unless I make a contact to the screen.How to fix this issue???</p>