question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What is the proper way to access QueryList results

See original GitHub issue

Accessing child components with the Query() annotation like this:

constructor(@Query(Type) query:Type) {

}

Gives us a QueryList object that comes with methods to add(), remove(), … etc.

The results of the query are located in query._results. Since it has an underscore in it’s name, I thought it might be rather considered private. But I couldn’t find a method getResults() or alike.

Is it okay-ish to access _results here, or is there a better way to get hold of them?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
hawaiikaoscommented, Mar 27, 2019

It seems shortsighted to not have this accessible by index (very frustrating to work with it).

2reactions
mheverycommented, Apr 28, 2015

No _results is private. The correct way is to iterate over it is using the ES6 construct.

for(var directive of queryList) {
  ...
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

angular 4 how to access ViewChildren _results - Stack Overflow
Call the toArray() method: this.hangchecks.toArray().forEach((item) => {.
Read more >
QueryList - Angular
This function is executed for each element of the query result list while comparing current query list with the new one (provided as...
Read more >
Angular - Understanding How To Use QueryList Properly.
In this post we will go through all the ways we can leverage the QueryList object ... Angular – Understanding how to use...
Read more >
Understanding ViewChildren, ContentChildren, and QueryList ...
Let's see how we can handle this with Angular. @ViewChildren —. Returns the specified elements or directives from the view DOM as QueryList....
Read more >
Understanding ViewChild, ViewChildren & Querylist in Angular
ViewChild & ViewChildren are used to Query & get the reference of the DOM element into component. ViewChild returns a element & ViewChildren ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found