diff --git a/modules/angular2/src/core/facade/collection.dart b/modules/angular2/src/core/facade/collection.dart index 1e5bb72628..e58c310be2 100644 --- a/modules/angular2/src/core/facade/collection.dart +++ b/modules/angular2/src/core/facade/collection.dart @@ -182,6 +182,10 @@ class ListWrapper { } static List slice(List l, [int from = 0, int to]) { + //in JS if from > to an empty array is returned + if(to != null && from > to) { + return []; + } return l.sublist(_startOffset(l, from), _endOffset(l, to)); } diff --git a/modules/angular2/test/core/facade/collection_spec.ts b/modules/angular2/test/core/facade/collection_spec.ts index dafdd322fa..bd3d2c3786 100644 --- a/modules/angular2/test/core/facade/collection_spec.ts +++ b/modules/angular2/test/core/facade/collection_spec.ts @@ -62,6 +62,9 @@ export function main() { it('should support negative end', () => { expect(ListWrapper.slice(l, -3, -1)).toEqual([2, 3]); }); + + it('should return empty list if start is greater than end', + () => { expect(ListWrapper.slice(l, 4, 2)).toEqual([]); }); }); describe('indexOf', () => {