Question presented to candidate: "Angular now has viewChild() and friends as functions. What changed compared with the @ViewChild decorator: the types, the timing, required queries, and how you react to changes? Would you migrate an existing component?"
What a strong answer should cover:
viewChild(),viewChildren(),contentChild(),contentChildren()return signals (Signal<T | undefined>,Signal<readonly T[]>); stable since v19 (developer preview in 17.2)..requiredremovesundefinedfrom the type; reading it too early is caught by the compiler (NG8118) or throws at runtime (NG0951).- No
staticoption and noQueryList: derived state iscomputed(), side effects areeffect()/afterRenderEffect(), instead ofngAfterViewInit+changes.subscribe. - They compile to a different instruction (
ɵɵviewQuerySignal) and need the Angular compiler: plain JIT does not register them. - Same locators and
readoption;contentChilddefaults todescendants: true. - Migration:
ng generate @angular/core:signal-queries-migration; decorators are not deprecated.
Clarifying questions expected:
- "Is the codebase already on signal inputs, or still decorator-based?"
- "Are there tests or libraries that read the query properties directly?"
Code / implementation expected: Yes — a component using viewChild.required, an optional viewChild inside @if, viewChildren with computed, and contentChild.