NG.I · Angular 22 practice question

A developer is working within a complex component structure using `@let` declarations. If a variable is declared inside a nested `@if` block, can that variable be referenced directly in the template of a sibling component?

<div *ngIf="condition"><span @let innerVar="10">...</span></div><div @let siblingVar="5">...</div>
Choose one answer
Check answer and explanation

Correct answer: No, because `@let` scopes are confined to the specific view boundary where they are declared.

Explanation

The correct answer is "No, because `@let` scopes are confined to the specific view boundary where they are declared." This aligns with the principle that declarations are not accessible outside their defined scope.

Common trap

The tempting incorrect answer suggesting global scope is wrong because the documentation explicitly states that declarations are not hoisted and cannot be accessed by parent views or siblings.

Source: Angular docs: Variables in templates — Variable scope
Checked against the cited text on 2026-11-25.

Report an error in this question