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']);