| OLD | NEW |
| 1 part of angular.filter; | 1 part of angular.formatter_internal; |
| 2 | 2 |
| 3 /** | 3 /** |
| 4 * Creates a new List or String containing only a prefix/suffix of the | 4 * Creates a new List or String containing only a prefix/suffix of the |
| 5 * elements as specified by the `limit` parameter. | 5 * elements as specified by the `limit` parameter. |
| 6 * | 6 * |
| 7 * When operating on a List, the returned list is always a copy even when all | 7 * When operating on a List, the returned list is always a copy even when all |
| 8 * the elements are being returned. | 8 * the elements are being returned. |
| 9 * | 9 * |
| 10 * When the `limit` expression evaluates to a positive integer, `limit` items | 10 * When the `limit` expression evaluates to a positive integer, `limit` items |
| 11 * from the beginning of the List/String are returned. When `limit` evaluates | 11 * from the beginning of the List/String are returned. When `limit` evaluates |
| (...skipping 15 matching lines...) Expand all Loading... |
| 27 * | 27 * |
| 28 * This [ng-repeat] directive: | 28 * This [ng-repeat] directive: |
| 29 * | 29 * |
| 30 * <li ng-repeat="i in 'abcdefghij' | limitTo:-2">{{i}}</li> | 30 * <li ng-repeat="i in 'abcdefghij' | limitTo:-2">{{i}}</li> |
| 31 * | 31 * |
| 32 * results in | 32 * results in |
| 33 * | 33 * |
| 34 * <li>i</li> | 34 * <li>i</li> |
| 35 * <li>j</li> | 35 * <li>j</li> |
| 36 */ | 36 */ |
| 37 @NgFilter(name:'limitTo') | 37 @Formatter(name:'limitTo') |
| 38 class LimitToFilter { | 38 class LimitTo implements Function { |
| 39 Injector _injector; | 39 Injector _injector; |
| 40 | 40 |
| 41 LimitToFilter(this._injector); | 41 LimitTo(this._injector); |
| 42 | 42 |
| 43 dynamic call(dynamic items, [int limit]) { | 43 dynamic call(dynamic items, [int limit]) { |
| 44 if (items == null) return null; | 44 if (items == null) return null; |
| 45 if (limit == null) return const[]; | 45 if (limit == null) return const[]; |
| 46 if (items is! List && items is! String) return items; | 46 if (items is! List && items is! String) return items; |
| 47 int i = 0, j = items.length; | 47 int i = 0, j = items.length; |
| 48 if (limit > -1) { | 48 if (limit > -1) { |
| 49 j = (limit > j) ? j : limit; | 49 j = (limit > j) ? j : limit; |
| 50 } else { | 50 } else { |
| 51 i = j + limit; | 51 i = j + limit; |
| 52 if (i < 0) i = 0; | 52 if (i < 0) i = 0; |
| 53 } | 53 } |
| 54 return items is String ? | 54 return items is String ? |
| 55 (items as String).substring(i, j) : | 55 (items as String).substring(i, j) : |
| 56 (items as List).getRange(i, j).toList(growable: false); | 56 (items as List).getRange(i, j).toList(growable: false); |
| 57 } | 57 } |
| 58 } | 58 } |
| OLD | NEW |