Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your plunkr was pretty complicated and hard to weed through so I re-created what you wanted using a fiddle. The general idea behind my approach is to filter out the items from the array, not the sub array. And only do the filtered items when the text changes. So here's the markup:</p> <pre><code>&lt;div ng-app="app"&gt; &lt;div ng-controller="ParentCtrl"&gt; &lt;input data-ng-model="filterText" data-ng-change="updateTypes()" /&gt; &lt;div data-ng-repeat="type in filteredTypes"&gt; {{ type.name }} &lt;ul&gt; &lt;li style="margin-left:20px;" data-ng-repeat="entry in type.entries"&gt; - {{ entry.name }} &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>And here's the code:</p> <pre><code>angular.module('app', []) function ParentCtrl($scope){ $scope.filterText = ""; $scope.types = [ { name: "type1", entries: [{ name: "name1"}, { name: "name2"}, { name: "name3"}]}, { name: "type2", entries: [{ name: "name1"}, { name: "name3"}, { name: "name3"}]}, { name: "type3", entries: [{ name: "name1"}, { name: "name2"}, { name: "name5"}]}, { name: "type4", entries: [{ name: "name4"}, { name: "name2"}, { name: "name3"}]} ]; $scope.filteredTypes = []; $scope.updateTypes = function(){ $scope.filteredTypes.length = 0; for(var x = 0; x &lt; $scope.types.length; x++){ if($scope.filterText === ""){ $scope.filteredTypes.push($scope.types[x]); } else{ var entries = []; for(var y = 0; y &lt; $scope.types[x].entries.length; y++){ if($scope.types[x].entries[y].name.indexOf($scope.filterText) !== -1){ entries.push($scope.types[x].entries[y]); } } if(entries.length &gt; 0){ $scope.filteredTypes.push({ name: $scope.types[x].name, entries: entries }); } } } } $scope.updateTypes(); } </code></pre> <p><strong>Fiddle</strong>: <a href="http://jsfiddle.net/2hRws/" rel="nofollow">http://jsfiddle.net/2hRws/</a></p> <p>The reason I'm creating a new array and not using an actual filter to remove the results is that angular doesn't like creating dynamic arrays on the fly in filters. This is because it doesn't assign $$hashKey and things just don't line up correctly when dirty checking. I got the idea of how to do what you needed from this topic on the matter: <a href="https://groups.google.com/forum/#!topic/angular/IEIQok-YkpU" rel="nofollow">https://groups.google.com/forum/#!topic/angular/IEIQok-YkpU</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload