feat(core): adds get method to QueryList (#36907)
This commit adds get method to QueryList. The method returns an item of the internal results by index number. PR Close #29467 PR Close #36907
This commit is contained in:
parent
ce604b909b
commit
a965589eb8
1
goldens/public-api/core/core.d.ts
vendored
1
goldens/public-api/core/core.d.ts
vendored
@ -756,6 +756,7 @@ export declare class QueryList<T> implements Iterable<T> {
|
|||||||
filter(fn: (item: T, index: number, array: T[]) => boolean): T[];
|
filter(fn: (item: T, index: number, array: T[]) => boolean): T[];
|
||||||
find(fn: (item: T, index: number, array: T[]) => boolean): T | undefined;
|
find(fn: (item: T, index: number, array: T[]) => boolean): T | undefined;
|
||||||
forEach(fn: (item: T, index: number, array: T[]) => void): void;
|
forEach(fn: (item: T, index: number, array: T[]) => void): void;
|
||||||
|
get(index: number): T | undefined;
|
||||||
map<U>(fn: (item: T, index: number, array: T[]) => U): U[];
|
map<U>(fn: (item: T, index: number, array: T[]) => U): U[];
|
||||||
notifyOnChanges(): void;
|
notifyOnChanges(): void;
|
||||||
reduce<U>(fn: (prevValue: U, curValue: T, curIndex: number, array: T[]) => U, init: U): U;
|
reduce<U>(fn: (prevValue: U, curValue: T, curIndex: number, array: T[]) => U, init: U): U;
|
||||||
|
@ -63,6 +63,13 @@ export class QueryList<T> implements Iterable<T> {
|
|||||||
if (!proto[symbol]) proto[symbol] = symbolIterator;
|
if (!proto[symbol]) proto[symbol] = symbolIterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the QueryList entry at `index`.
|
||||||
|
*/
|
||||||
|
get(index: number): T|undefined {
|
||||||
|
return this._results[index];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See
|
* See
|
||||||
* [Array.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
|
* [Array.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
|
||||||
|
@ -51,6 +51,11 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testin
|
|||||||
expect(queryList.length).toEqual(2);
|
expect(queryList.length).toEqual(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should support get', () => {
|
||||||
|
queryList.reset(['one', 'two']);
|
||||||
|
expect(queryList.get(1)).toEqual('two');
|
||||||
|
});
|
||||||
|
|
||||||
it('should support map', () => {
|
it('should support map', () => {
|
||||||
queryList.reset(['one', 'two']);
|
queryList.reset(['one', 'two']);
|
||||||
expect(queryList.map((x) => x)).toEqual(['one', 'two']);
|
expect(queryList.map((x) => x)).toEqual(['one', 'two']);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user