<h1><code ng:non-bindable="">filter</code>
<span class="hint">(filter in module <code ng:non-bindable="">ng</code>
)</span>
</h1>
<div><h2 id="Description">Description</h2>
<div class="description"><p>Selects a subset of items from <code>array</code> and returns it as a new array.</p>

<p>Note: This function is used to augment the <code>Array</code> type in Angular expressions. See
<a href="api/angular.module.ng.$filter"><code>angular.module.ng.$filter</code></a> for more information about Angular arrays.</p></div>
<h2 id="Usage">Usage</h2>
<div class="usage"><h3 id="In.HTML.Template.Binding">In HTML Template Binding</h3>
<div class="in-html-template-binding"><code ng:non-bindable="">{{ filter_expression | filter:expression }}</code>
</div>
<h3 id="In.JavaScript">In JavaScript</h3>
<div class="in-javascript"><code ng:non-bindable="">$filter('filter')(array, expression)</code>
</div>
<h3 id="Parameters">Parameters</h3>
<ul class="parameters"><li><code ng:non-bindable="">array – {Array} – </code>
<p>The source array.</p></li>
<li><code ng:non-bindable="">expression – {string|Object|function()} – </code>
<p>The predicate to be used for selecting items from
<code>array</code>.</p>

<p>Can be one of:</p>

<ul>
<li><p><code>string</code>: Predicate that results in a substring match using the value of <code>expression</code>
string. All strings or objects with string properties in <code>array</code> that contain this string
will be returned. The predicate can be negated by prefixing the string with <code>!</code>.</p></li>
<li><p><code>Object</code>: A pattern object can be used to filter specific properties on objects contained
by <code>array</code>. For example <code>{name:"M", phone:"1"}</code> predicate will return an array of items
which have property <code>name</code> containing "M" and property <code>phone</code> containing "1". A special
property name <code>$</code> can be used (as in <code>{$:"text"}</code>) to accept a match against any
property of the object. That's equivalent to the simple substring match with a <code>string</code>
as described above.</p></li>
<li><p><code>function</code>: A predicate function can be used to write arbitrary filters. The function is
called for each element of <code>array</code>. The final result is an array of those elements that
the predicate returned true for.</p></li>
</ul></li>
</ul>
</div>
<h2 id="Example">Example</h2>
<div class="example"><h3>Demo Source Code</h3>
<div source-edit="" source-edit-deps="angular.js" source-edit-html="index.html-170" source-edit-css="" source-edit-js="" source-edit-unit="" source-edit-scenario="scenario.js-171"></div>
<div class="tabbable"><div class="tab-pane" title="index.html">
<pre class="prettyprint linenums" ng-set-text="index.html-170" ng-html-wrap=" angular.js"></pre>
<script type="text/ng-template" id="index.html-170">
  <div ng-init="friends = [{name:'John', phone:'555-1276'},
                           {name:'Mary', phone:'800-BIG-MARY'},
                           {name:'Mike', phone:'555-4321'},
                           {name:'Adam', phone:'555-5678'},
                           {name:'Julie', phone:'555-8765'}]"></div>

  Search: <input ng-model="searchText">
  <table id="searchTextResults">
    <tr><th>Name</th><th>Phone</th><tr>
    <tr ng-repeat="friend in friends | filter:searchText">
      <td>{{friend.name}}</td>
      <td>{{friend.phone}}</td>
    <tr>
  </table>
  <hr>
  Any: <input ng-model="search.$"> <br>
  Name only <input ng-model="search.name"><br>
  Phone only <input ng-model="search.phone"å><br>
  <table id="searchObjResults">
    <tr><th>Name</th><th>Phone</th><tr>
    <tr ng-repeat="friend in friends | filter:search">
      <td>{{friend.name}}</td>
      <td>{{friend.phone}}</td>
    <tr>
  </table>
</script>
</div>
<div class="tab-pane" title="End to end test">
<pre class="prettyprint linenums" ng-set-text="scenario.js-171"></pre>
<script type="text/ng-template" id="scenario.js-171">
  it('should search across all fields when filtering with a string', function() {
    input('searchText').enter('m');
    expect(repeater('#searchTextResults tr', 'friend in friends').column('friend.name')).
      toEqual(['Mary', 'Mike', 'Adam']);

    input('searchText').enter('76');
    expect(repeater('#searchTextResults tr', 'friend in friends').column('friend.name')).
      toEqual(['John', 'Julie']);
  });

  it('should search in specific fields when filtering with a predicate object', function() {
    input('search.$').enter('i');
    expect(repeater('#searchObjResults tr', 'friend in friends').column('friend.name')).
      toEqual(['Mary', 'Mike', 'Julie']);
  });
</script>
</div>
</div><h3>Demo Source Code</h3>
<div class="well  doc-example-live" ng-embed-app="" ng-set-html="index.html-170" ng-eval-javascript=""></div></div>
</div>
