diff --git a/goldens/public-api/core/core.d.ts b/goldens/public-api/core/core.d.ts index 5a861d8adb..712fd46125 100644 --- a/goldens/public-api/core/core.d.ts +++ b/goldens/public-api/core/core.d.ts @@ -756,6 +756,7 @@ export declare class QueryList implements Iterable { filter(fn: (item: T, index: number, array: T[]) => boolean): T[]; find(fn: (item: T, index: number, array: T[]) => boolean): T | undefined; forEach(fn: (item: T, index: number, array: T[]) => void): void; + get(index: number): T | undefined; map(fn: (item: T, index: number, array: T[]) => U): U[]; notifyOnChanges(): void; reduce(fn: (prevValue: U, curValue: T, curIndex: number, array: T[]) => U, init: U): U; diff --git a/packages/core/src/linker/query_list.ts b/packages/core/src/linker/query_list.ts index 2ada13c579..24f7f87b06 100644 --- a/packages/core/src/linker/query_list.ts +++ b/packages/core/src/linker/query_list.ts @@ -63,6 +63,13 @@ export class QueryList implements Iterable { if (!proto[symbol]) proto[symbol] = symbolIterator; } + /** + * Returns the QueryList entry at `index`. + */ + get(index: number): T|undefined { + return this._results[index]; + } + /** * See * [Array.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) diff --git a/packages/core/test/linker/query_list_spec.ts b/packages/core/test/linker/query_list_spec.ts index 1952621096..f79b137548 100644 --- a/packages/core/test/linker/query_list_spec.ts +++ b/packages/core/test/linker/query_list_spec.ts @@ -51,6 +51,11 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testin expect(queryList.length).toEqual(2); }); + it('should support get', () => { + queryList.reset(['one', 'two']); + expect(queryList.get(1)).toEqual('two'); + }); + it('should support map', () => { queryList.reset(['one', 'two']); expect(queryList.map((x) => x)).toEqual(['one', 'two']);