NG.I · Angular 22 practice question

A developer is building a custom UI component, `mapRenderer`, which implements a directive and uses `exportAs: 'mapRef'`. In their component template, they need to access the directive instance to call a method on it. Which syntax correctly provides access to the directive instance?

<mapRenderer #mapInstance="mapRef" />
Choose one answer
Check answer and explanation

Correct answer: <mapRenderer #mapInstance="mapRef" />

Explanation

The syntax "<mapRenderer #mapInstance=\"mapRef\" />" correctly assigns the directive instance because the directive specified 'mapRef' via its exportAs property.

Common trap

Using 'instance' or 'directive' would fail because the template variable must match the name defined in the directive's exportAs property.

Source: Angular docs: Variables in templates — Assigning values to template reference variables
Checked against the cited text on 2026-11-25.

Report an error in this question