From b634a25ae0180e9bfddaeb109b39d9044440e610 Mon Sep 17 00:00:00 2001 From: laco0416 Date: Fri, 8 Jan 2016 15:34:25 +0900 Subject: [PATCH] feat(core): Add `QueryList#forEach` --- modules/angular2/src/core/linker/query_list.ts | 5 +++++ modules/angular2/test/core/linker/query_list_spec.ts | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/modules/angular2/src/core/linker/query_list.ts b/modules/angular2/src/core/linker/query_list.ts index d969a524c2..5341d46d6a 100644 --- a/modules/angular2/src/core/linker/query_list.ts +++ b/modules/angular2/src/core/linker/query_list.ts @@ -51,6 +51,11 @@ export class QueryList { */ reduce(fn: (acc: U, item: T) => U, init: U): U { return this._results.reduce(fn, init); } + /** + * executes function for each element in a query. + */ + forEach(fn: (item: T) => void): void { this._results.forEach(fn); } + /** * converts QueryList into an array */ diff --git a/modules/angular2/test/core/linker/query_list_spec.ts b/modules/angular2/test/core/linker/query_list_spec.ts index fe284347dc..e02f309d9f 100644 --- a/modules/angular2/test/core/linker/query_list_spec.ts +++ b/modules/angular2/test/core/linker/query_list_spec.ts @@ -50,6 +50,13 @@ export function main() { expect(queryList.map((x) => x)).toEqual(['one', 'two']); }); + it('should support forEach', () => { + queryList.reset(['one', 'two']); + let join = ''; + queryList.forEach((x) => join = join + x); + expect(join).toEqual('onetwo'); + }); + if (!IS_DART) { it('should support filter', () => { queryList.reset(['one', 'two']);