export Query : QueryFactory
export Query : QueryFactory
exported from angular2/core defined in angular2/src/core/metadata.ts (line 1051)
Declares an injectable parameter to be a live list of directives or variable bindings from the content children of a directive.
Example (live demo)
Assume that <tabs>
component would like to get a list its children <pane>
components as shown in this example:
The preferred solution is to query for Pane
directives using this decorator.
A query can look for variable bindings by passing in a string with desired binding symbol.
Example (live demo)
In this case the object that is injected depend on the type of the variable binding. It can be an ElementRef, a directive or a component.
Passing in a comma separated list of variable bindings will query for all of them.
Configure whether query looks for direct children or all descendants
of the querying element, by using the descendants
parameter.
It is set to false
by default.
Example (live demo)
When querying for items, the first container will see only a
and b
by default,
but with Query(TextDirective, {descendants: true})
it will see c
too.
The queried directives are kept in a depth-first pre-order with respect to their positions in the DOM.
Query does not look deep into any subcomponent views.
Query is updated as part of the change-detection cycle. Since change detection happens after construction of a directive, QueryList will always be empty when observed in the constructor.
The injected object is an unmodifiable live list.
See QueryList
for more details.