forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.Array.filter.html
65 lines (61 loc) · 3.18 KB
/
angular.Array.filter.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<h1>angular.Array.filter</h1>
<div class="angular-array-filter"><h2>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="#!angular.Array"><code>angular.Array</code></a> for more info.</p></div>
<h2>Dependencies</h2>
<ul class="dependencies"></ul>
<h2>Usage</h2>
<div class="usage"><div ng:non-bindable=""><pre class="brush: js; html-script: true;">angular.Array.filter(array, expression);</pre>
</div>
<h3>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>Example</h2>
<div class="example"><doc:example><doc:source><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 name="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 name="search.$"/> <br>
Name only <input name="search.name"/><br>
Phone only <input name="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></doc:source>
</doc:example>
</div>
</div>