diff options
| author | Igor Minar | 2010-11-23 14:10:10 -0800 | 
|---|---|---|
| committer | Igor Minar | 2010-11-23 14:10:10 -0800 | 
| commit | 0d1f8a053214e0aa98ffa4a9630eb2ddd0daff6e (patch) | |
| tree | b2401408d1dcc81839b3200683f22537cc16af52 /src/apis.js | |
| parent | b94600d71e90a9f93e507b2cac0ffc2c55e7857a (diff) | |
| download | angular.js-0d1f8a053214e0aa98ffa4a9630eb2ddd0daff6e.tar.bz2 | |
docs for angular.Array.count
Diffstat (limited to 'src/apis.js')
| -rw-r--r-- | src/apis.js | 38 | 
1 files changed, 38 insertions, 0 deletions
| diff --git a/src/apis.js b/src/apis.js index 6dd41fc4..b77161fb 100644 --- a/src/apis.js +++ b/src/apis.js @@ -239,6 +239,44 @@ var angularArray = {     * @ngdoc function     * @name angular.Array.count     * @function +   * +   * @description +   * Determines the number of elements in an array. Optionally it will count only those elements +   * for which the `condition` evaluets to `true`. +   * +   * Note: this function is used to augment the Array type in angular expressions. See +   * {@link angular.Array} for more info. +   * +   * @param {Array} array The array to count elements in. +   * @param {(Function()|string)=} condition A function to be evaluated or angular expression to be +   *     compiled and evaluated. The element that is currently being iterated over, is exposed to +   *     the `condition` as `this`. +   * @returns {number} Number of elements in the array (for which the condition evaluates to true). +   * +   * @example +     <pre ng:init="items = [{name:'knife', points:1}, +                            {name:'fork', points:3}, +                            {name:'spoon', points:1}]"></pre> +     <ul> +       <li ng:repeat="item in items"> +          {{item.name}}: points= +          <input type="text" name="item.points"/> <!-- id="item{{$index}} --> +       </li> +     </ul> +     <p>Number of items which have one point: <em>{{ items.$count('points==1') }}</em></p> +     <p>Number of items which have more than one point: <em>{{items.$count('points>1')}}</em></p> + +     @scenario +     it('should calculate counts', function() { +       expect(binding('items.$count(\'points==1\')')).toEqual(2); +       expect(binding('items.$count(\'points>1\')')).toEqual(1); +     }); + +     it('should recalculate when updated', function() { +       using('.doc-example li:first-child').input('item.points').enter('23'); +       expect(binding('items.$count(\'points==1\')')).toEqual(1); +       expect(binding('items.$count(\'points>1\')')).toEqual(2); +     });     */    'count':function(array, condition) {      if (!condition) return array.length; | 
