X Tutup
Skip to content

Commit b634a25

Browse files
laco0416Matias Niemela
authored andcommitted
feat(core): Add QueryList#forEach
1 parent c1a0af5 commit b634a25

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

modules/angular2/src/core/linker/query_list.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ export class QueryList<T> {
5151
*/
5252
reduce<U>(fn: (acc: U, item: T) => U, init: U): U { return this._results.reduce(fn, init); }
5353

54+
/**
55+
* executes function for each element in a query.
56+
*/
57+
forEach(fn: (item: T) => void): void { this._results.forEach(fn); }
58+
5459
/**
5560
* converts QueryList into an array
5661
*/

modules/angular2/test/core/linker/query_list_spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export function main() {
5050
expect(queryList.map((x) => x)).toEqual(['one', 'two']);
5151
});
5252

53+
it('should support forEach', () => {
54+
queryList.reset(['one', 'two']);
55+
let join = '';
56+
queryList.forEach((x) => join = join + x);
57+
expect(join).toEqual('onetwo');
58+
});
59+
5360
if (!IS_DART) {
5461
it('should support filter', () => {
5562
queryList.reset(['one', 'two']);

0 commit comments

Comments
 (0)
X Tutup