forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.foreach.html
39 lines (38 loc) · 1.56 KB
/
angular.foreach.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
<h1>angular.foreach</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>Invokes the <code>iterator</code> function once for each item in <code>obj</code> collection. The collection can either
be an object or an array. The <code>iterator</code> function is invoked with <code>iterator(value, key)</code>, where
<code>value</code> is the value of an object property or an array element and <code>key</code> is the object property
key or array element index. Optionally, <code>context</code> can be specified for the iterator function.</p><div ng:non-bindable><pre class="brush: js; html-script: true;">
var values = {name: 'misko', gender: 'male'};
var log = [];
angular.foreach(values, function(value, key){
this.push(key + ': ' + value);
}, log);
expect(log).toEqual(['name: misko', 'gender:male']);
</pre></div>
<h2>Usage</h2>
<tt ng:non-bindable>
angular.foreach(obj, iterator, context);
</tt>
<h3>Parameters</h3>
<ul>
<li><tt>obj</tt> –
<tt>{Object|Array}</tt>
<tt></tt>
– Object to iterate over.</li>
<li><tt>iterator</tt> –
<tt>{function()}</tt>
<tt></tt>
– Iterator function.</li>
<li><tt>context</tt> –
<tt>{Object}</tt>
<tt></tt>
– Object to become context (<code>this</code>) for the iterator function.</li>
</ul>
<h3>Returns</h3>
<tt>{Objet|Array}</tt> Reference to <code>obj</code>.