forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.Object.size.html
43 lines (42 loc) · 1.76 KB
/
angular.Object.size.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
<h1>angular.Object.size</h1>
<div class="angular-object-size"><h2>Description</h2>
<div class="description"><p>Determines the number of elements in an array, the number of properties an object has, or
the length of a string.</p>
<p>Note: This function is used to augment the Object type in Angular expressions. See
<a href="#!/api/angular.Object"><code>angular.Object</code></a> for more information about Angular arrays.</p></div>
<h2>Usage</h2>
<div class="usage"><div ng:non-bindable=""><pre class="brush: js; html-script: true;">angular.Object.size(obj, ownPropsOnly);</pre>
</div>
<h3>Parameters</h3>
<ul class="parameters"><li><code ng:non-bindable="">obj – {Object|Array|string} – </code>
<p>Object, array, or string to inspect.</p></li>
<li><code ng:non-bindable="">ownPropsOnly – {boolean} – </code>
<p>Count only "own" properties in an object</p></li>
</ul>
<h3>Returns</h3>
<div class="returns"><code ng:non-bindable="">{number}</code>
– <p>The size of <code>obj</code> or <code>0</code> if <code>obj</code> is neither an object nor an array.</p></div>
</div>
<h2>Example</h2>
<div class="example"><doc:example>
<pre class="doc-source">
<script>
function SizeCtrl() {
this.fooStringLength = angular.Object.size('foo');
}
</script>
<div ng:controller="SizeCtrl">
Number of items in array: {{ [1,2].$size() }}<br/>
Number of items in object: {{ {a:1, b:2, c:3}.$size() }}<br/>
String length: {{fooStringLength}}
</div>
</pre>
<pre class="doc-scenario">
it('should print correct sizes for an array and an object', function() {
expect(binding('[1,2].$size()')).toBe('2');
expect(binding('{a:1, b:2, c:3}.$size()')).toBe('3');
expect(binding('fooStringLength')).toBe('3');
});
</pre>
</doc:example></div>
</div>