MCPcopy Create free account
hub / github.com/angular/angular / QueryList

Class QueryList

packages/core/src/linker/query_list.ts:46–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44 * @see [Using QueryList](guide/components/queries#using-querylist)
45 */
46export class QueryList<T> implements Iterable<T> {
47 public readonly dirty = true;
48 private _onDirty?: () => void = undefined;
49 private _results: Array<T> = [];
50 private _changesDetected: boolean = false;
51 private _changes: Subject<QueryList<T>> | undefined = undefined;
52
53 readonly length: number = 0;
54 readonly first: T = undefined!;
55 readonly last: T = undefined!;
56
57 /**
58 * Returns `Observable` of `QueryList` notifying the subscriber of changes.
59 */
60 get changes(): Observable<any> {
61 return (this._changes ??= new Subject());
62 }
63
64 /**
65 * @param emitDistinctChangesOnly Whether `QueryList.changes` should fire only when actual change
66 * has occurred. Or if it should fire when query is recomputed. (recomputing could resolve in
67 * the same result)
68 */
69 constructor(private _emitDistinctChangesOnly: boolean = false) {}
70
71 /**
72 * Returns the QueryList entry at `index`.
73 */
74 get(index: number): T | undefined {
75 return this._results[index];
76 }
77
78 /**
79 * See
80 * [Array.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
81 */
82 map<U>(fn: (item: T, index: number, array: T[]) => U): U[] {
83 return this._results.map(fn);
84 }
85
86 /**
87 * See
88 * [Array.filter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
89 */
90 filter<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S): S[];
91 filter(predicate: (value: T, index: number, array: readonly T[]) => unknown): T[];
92 filter(fn: (item: T, index: number, array: T[]) => boolean): T[] {
93 return this._results.filter(fn);
94 }
95
96 /**
97 * See
98 * [Array.find](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
99 */
100 find(fn: (item: T, index: number, array: T[]) => boolean): T | undefined {
101 return this._results.find(fn);
102 }
103

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected