Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A filter on <code>ng-repeat</code> will only take into account what is <em>in</em> the object. Not what might be displayed while the loop is running. You could however populate <code>friends</code> with the real data and then the filter should work.</p> <p>Usage:</p> <pre><code>&lt;ul&gt; &lt;li ng-repeat="friend in friends | injectItemTitles:'itemTitles' | filter:personFilter"&gt; &lt;span&gt;{{friend.name}}&lt;/span&gt; &lt;span&gt;{{friend.phone}}&lt;/span&gt; &lt;span&gt;{{friend.itemTitles.join(', ')}}&lt;/span&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>Demo: <a href="http://jsbin.com/iciyoq/2/" rel="nofollow">http://jsbin.com/iciyoq/2/</a></p> <p>There might be one problem with this approach, as it whould <em>inject</em> the item titels on each <em>digest cycle</em>. So it could be better to apply the <code>injectItemTitles</code>-filter in the controller on large datasets.</p> <hr> <p>Full code:</p> <pre><code>(function (app, ng) { 'use strict'; app.controller('MainCtrl', ['$scope', function($scope) { $scope.friends = [{ name: 'John', phone: '555-1276', items : ['id0', 'id1'] }, { name: 'Mary', phone: '800-BIG-MARY', items : ['id1', 'id2'] }, { name: 'Mike', phone: '555-4321', items : ['id2', 'id3'] }, { name: 'Adam', phone: '555-5678', items : ['id3', 'id4'] }, { name: 'Julie', phone: '555-8765', items : ['id4', 'id5'] }]; }]); app.filter('injectItemTitles', ['AllItems', 'getItemTitlesFilter', function(AllItems, getItemTitlesFilter) { return function(friends, prop){ return friends.map(function(friend) { friend[prop] = getItemTitlesFilter(friend.items); return friend; }); }; }]); app.filter('getItemTitles', ['AllItems', function(AllItems){ return function(items){ return items.map(function (id) { return AllItems[id]; }); }; }]); app.service('AllItems', function(){ return { 'id0' : 'aaa', 'id1' : 'aab', 'id2' : 'aba', 'id3' : 'abb', 'id4' : 'baa', 'id5' : 'bab', 'id6' : 'bba', 'id7' : 'bbb' }; }); }(angular.module('app', []), angular)); </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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