NG.I · Angular 22 practice question

A developer is building a parent component that renders several child components. They attempt to use `viewChild` to access a property from a deeply nested grandchild component within the parent's template. What will be the outcome of this operation?

parentTemplate: 
  <child-a>
    <grandchild-b></grandchild-b>
  </child-a>
Choose one answer
Check answer and explanation

Correct answer: The query will return undefined because view queries are restricted to elements directly defined within the querying component's template.

Explanation

The correct outcome is that the query will return undefined because view queries are limited to elements explicitly declared within the querying component's template.

Common trap

The assertion that 'the query will successfully retrieve the grandchild component instance because Angular's view queries traverse the entire component tree' is incorrect because view queries do not cross component boundaries. Furthermore, the claim that 'the query will return an array of all matching components, as `viewChild` defaults to returning a collection when nesting is involved' is wrong because `viewChild` is designed to fetch only a single result.

Source: Angular docs: Referencing component children with queries — View queries
Checked against the cited text on 2026-11-25.

Report an error in this question