Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Angular error NG0951 means a required singular child query found no matching child. Check whether you used viewChild.required() or contentChild.required(), then verify that its locator matches an element or provider in the correct template region and that control flow has not removed the target. If the child is legitimately optional, use the non-required query and handle its possible undefined result.

Why does Angular say a required child query has no value?

A required query asserts that a matching child must exist. Angular reports NG0951 when it evaluates that query and no matching result is available. A target can be missing because the locator does not match, it is outside the query’s template scope, or a condition such as @if means it is not rendered.

With a singular optional viewChild() or contentChild(), no match can instead produce undefined. The required variants enforce presence, so their signal types do not include undefined. Use the required form only when the target is an invariant of the component.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

First identify the query and where it searches

Query Search area Default matching behavior
viewChild The querying component’s own template Finds one matching child, if present
contentChild Content supplied to the querying component Traverses descendants by default
viewChildren The querying component’s own template Returns a collection
contentChildren Content supplied to the querying component Finds direct children by default; descendant traversal can be configured

Queries do not cross component template boundaries. A view query cannot see into a child component’s own template, and a content query must find its target in the content supplied to the querying component. See Angular’s query guide for query scope and matching behavior.

How to troubleshoot NG0951

  1. Find the failing declaration. Look for viewChild.required(...) or contentChild.required(...). Confirm that the error comes from a singular required query, not a plural query that returns a collection.
  2. Check the locator. If the query uses a string, verify that the intended template reference has the same name. If it uses a component, directive, or provider token, verify that the target actually exposes that token in the relevant template.
  3. Check the template region. For viewChild, the target must be in the querying component’s own view. For contentChild, check that the caller supplies the target as projected content. A target inside another component’s template is not visible through that component boundary.
  4. Check conditional rendering. Inspect @if, @for, and other conditions around the target. If the target is not present when the required query is read, the query has no match.
  5. Decide whether presence is mandatory. If the child may be absent by design, change to the optional query and make consuming code handle undefined. If it must exist, keep the required query and correct the locator, scope, or rendering logic.

Choose required or optional based on the component contract

Use a required singular query when the component cannot function without the matching child and its template structure guarantees that child is present. Use the optional form when absence is a valid state, such as a target shown only after a user action. In that case, code that reads the query must account for the result being undefined.

Do not switch to an optional query merely to suppress NG0951 if the child is genuinely required: that can hide a template or locator defect and move the failure into later code. Conversely, a required query is the wrong contract when conditional rendering intentionally allows no match.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check the Angular version and query API style

The signal-based viewChild and contentChild initializer APIs are documented as stable since Angular v19.0. Check the project’s installed Angular version before adopting that syntax in an older project. Angular also documents decorator-based @ViewChild and @ContentChild separately; their syntax and timing options differ. Follow the API style already used by the project and consult the relevant viewChild, contentChild, ViewChild, or ContentChild API reference.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.