Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/angular2/src/core/linker/query_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export class QueryList<T> {
*/
reduce<U>(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
*/
Expand Down
7 changes: 7 additions & 0 deletions modules/angular2/test/core/linker/query_list_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
1 change: 1 addition & 0 deletions tools/public_api_guard/public_api_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ const CORE = [
'QueryList.changes:Observable<any>',
'QueryList.filter(fn:(item: T) => boolean):T[]',
'QueryList.first:T',
'QueryList.forEach(fn:(item: T) => void):void',
'QueryList.last:T',
'QueryList.length:number',
'QueryList.map(fn:(item: T) => U):U[]',
Expand Down