forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.Array.indexOf.html
45 lines (43 loc) · 1.69 KB
/
angular.Array.indexOf.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
<h1>angular.Array.indexOf</h1>
<fieldset class="workInProgress">
<legend>Work In Progress</legend>
This page is currently being revised. It might be incomplete or contain inaccuracies.
</fieldset>
<h2>Description</h2>
<p>Determines the index of <code>value</code> in <code>array</code>.</p>
<p>Note: this function is used to augment the Array type in angular expressions. See
<a href="#!angular.Array"><code>angular.Array</code></a> for more info.</p>
<h2>Usage</h2>
<tt ng:non-bindable>
angular.Array.indexOf(array, value);
</tt>
<h3>Parameters</h3>
<ul>
<li><tt>array</tt> –
<tt>{Array}</tt>
<tt></tt>
– Array to search.</li>
<li><tt>value</tt> –
<tt>{*}</tt>
<tt></tt>
– Value to search for.</li>
</ul>
<h3>Returns</h3>
<tt>{number}</tt> The position of the element in <code>array</code>. The position is 0-based. <code>-1</code> is returned if the value can't be found.
<h2>Example</h2>
<doc:example>
<doc:source>
<div ng:init="books = ['Moby Dick', 'Great Gatsby', 'Romeo and Juliet']"></div>
<input name='bookName' value='Romeo and Juliet'> <br>
Index of '{{bookName}}' in the list {{books}} is <em>{{books.$indexOf(bookName)}}</em>.
</doc:source>
<doc:scenario> it('should correctly calculate the initial index', function() {
expect(binding('books.$indexOf(bookName)')).toBe('2');
});
it('should recalculate', function() {
input('bookName').enter('foo');
expect(binding('books.$indexOf(bookName)')).toBe('-1');
input('bookName').enter('Moby Dick');
expect(binding('books.$indexOf(bookName)')).toBe('0');
});</doc:scenario>
</doc:example>