QueryList<T>.get(index)
See original GitHub issueπ feature request
Relevant Package
This feature request is for @angular/core
Description
Now there is no way to get element from QueryList<T>
by index.
Describe the solution youβd like
Add method get(index)
to QueryList
export class QueryList<T> {
// ...
get(index: number): T|undefined {
return this._results[index];
}
// ...
}
Describe alternatives youβve considered
Very expensive workaround:
function getQueryListItemByIndex<T>(list: QueryList<T>, index: number): T|undefined {
let value;
let found = list.some((x, i) => {
if (i === index) {
value = x;
return true;
}
return false;
});
if (found) {
return value;
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:15
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Angular how to get index from viewChildren queryList items?
I've made a demo in which everything works (looping through viewChildren and getting the index). Try to compare this, maybe you've made aΒ ......
Read more >Use ViewChildren to get the QueryList of elements or ...
Use ViewChildren to get the QueryList of elements or directives from the view DOM. In many cases you have used the ViewChild decorator...
Read more >Angular how to get index from viewChildren queryList items?
I've made a demo in which everything works (looping through viewChildren and getting the index). Try to compare this, maybe you've made a...
Read more >Angular - Understanding How To Use QueryList Properly.
Use to get the QueryList of elements or directives from the view ... Iterator<T> get(index: number): T | undefined map<U>(fn: (item: T,Β ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@pkozlowski-opensource Even if not a performance bottleneck, it just seems like an oversight that the Angular team provided all of these array-mirroring methods like
forEach
andmap
for interacting with QueryLists, but didnβt provide a method for accessing an item by index. I agree with OP, this would be a great feature to have.Sure, if you see it as a performance bottleneck in your application after perf-measuring itβ¦