Components and templates: Angular 22 practice questions

Components and templates is 18% of the free Angular 22 mock (9 of 50 questions). Pick an answer to see right away whether it is correct, with the explanation and the documentation section it comes from.

NG.I · Angular 22 practice question

A developer is applying both a custom structural directive and a component to the same host element in an Angular template. They rely on the component's `ngOnInit` running strictly before the directive's `ngOnInit`. What is the safest architectural assumption to make regarding this execution order?

<div app-my-component app-my-directive></div>
Choose one answer
Check answer and explanation

Correct answer: The framework offers no guaranteed ordering between the component's and the directive's lifecycle hooks when applied to the same host element.

Explanation

The accurate statement is that the framework offers no guaranteed ordering between the component's and the directive's lifecycle hooks when applied to the same host element, as the official documentation explicitly states that no ordering is guaranteed.

Common trap

The assertion that the execution order is strictly guaranteed by the Angular framework to be component initialization followed by directive initialization implies a strict, predictable dependency, which is what the documentation warns against. Similarly, the suggestion that the framework provides a predictable sequence for when the component and associated directives execute their lifecycle hooks on the same element is also false.

Source: Angular docs: Component Lifecycle — Ordering with directives
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is building a component where a user's current theme setting is managed by an Angular signal. How must the developer access the theme value within the component's template to ensure the UI updates automatically when the signal changes?

theme = signal('dark');

// In template:
<p>Theme is: {{ theme }}</p>
Choose one answer
Check answer and explanation

Correct answer: {{ theme() }}

Explanation

The correct approach, as demonstrated for signals, is to call the signal function in the template: "Your color preference is {{ theme() }}."

Common trap

Using `{{ theme }}` treats the signal object as a primitive value, which does not trigger reactivity for signals. Using `{{ theme.value }}` is an outdated or incorrect pattern for accessing signal values in the template.

Source: Angular docs: Binding dynamic text, properties and attributes — Render dynamic text with text interpolation
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is building a custom component that must reflect a value passed down from its parent. They use `input()` to define the property. Which statement accurately describes how this input value can be accessed within the child component's logic?

import {Component, input, computed} from '@angular/core';

@Component({selector: 'app-slider'}) 
export class CustomSlider {
  sliderValue = input(10);
  displayLabel = computed(() => `Current: ${this.sliderValue()}`);
}
Choose one answer
Check answer and explanation

Correct answer: The value must be accessed by invoking the signal function, e.g., `this.sliderValue()`.

Explanation

To retrieve the data from a signal established using the `input()` function, one must invoke the signal as a callable function, matching the pattern shown in `this.sliderValue()` and consistent with the official documentation for reading input signals.

Common trap

Treating the signal as a direct property, such as accessing it via `this.sliderValue`, is incorrect for signals. Furthermore, assuming that Angular automatically unwraps the input signal, allowing access like `this.sliderValue.value`, is a misunderstanding of how Angular's input signals operate.

Source: Angular docs: Accepting data with input properties — Reading inputs
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


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

Open this question on its own page


NG.I · Angular 22 practice question

A developer is building a dashboard component. They have created a reusable `DataCard` component with the selector `app-data-card`. To display this card within the main dashboard's template, what must the developer ensure?

<app-data-card></app-data-card>
Choose one answer
Check answer and explanation

Correct answer: The dashboard component must import `DataCard` into its `imports` array to enable the usage of the `<app-data-card>` tag.

Explanation

The proper method involves ensuring the dashboard component includes `DataCard` within its `imports` array, as Angular requires knowledge of the component to render it when the corresponding selector appears in the template.

Common trap

Stating that `DataCard` must have `standalone: true` is overly restrictive; while this configuration is frequently used, the fundamental mechanism for template rendering relies on importing the component. Furthermore, suggesting the dashboard component should use `ViewChildren` describes a querying mechanism, not the process of component instantiation.

Source: Angular docs: guide/components/anatomy-of-components — Showing components in a template
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is building an input component and needs to capture specific details about a key press event within the template binding. If they use `(keyup)='handleKey($event)'`, what structure is guaranteed to be passed into the `handleKey` method?

<input type="text" (keyup)="handleKey($event)" />
Choose one answer
Check answer and explanation

Correct answer: An object containing the raw DOM event data, allowing access to properties like event.key.

Explanation

The appropriate selection is 'An object containing the raw DOM event data, allowing access to properties like event.key' because the `$event` variable supplied to the handler holds a reference to the actual event object.

Common trap

The choice stating 'A simple boolean indicating if the key press was successful, as Angular abstracts the event details' is inaccurate because Angular does not simplify the event details into a mere success boolean. Furthermore, the selection 'A string representation of the input field's current value, replacing the need for a full event object' is incorrect because `$event` furnishes the event object, not the current input value directly.

Source: Angular docs: Adding event listeners — Accessing the event argument
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is building a parent component that needs to synchronize a local state variable, `currentSetting`, with a child component's input property, `settingValue`, which is designed to update the parent when changed. Which binding syntax should the parent use in its template to achieve this automatic two-way synchronization?

<app-child [(settingValue)]="currentSetting" />
Choose one answer
Check answer and explanation

Correct answer: [(settingValue)]="currentSetting"

Explanation

The syntax `[(settingValue)]="currentSetting"` is the mechanism described for linking a plain property to a model input, ensuring both components' values remain in sync.

Common trap

Using only `settingValue="currentSetting"` would only push data down from the parent to the child, failing to propagate changes back up to the parent's state.

Source: Angular docs: Accepting data with input properties — Two-way binding with plain properties
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


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

Open this question on its own page


NG.I · Angular 22 practice question

A developer is building a reusable component, `VolumeControl`, that emits a signal when the volume changes. They want the consuming component's template to listen for an event named `volumeUpdated` instead of the default `volumeChanged` name. How should they configure the output property in the component's TypeScript file?

export class VolumeControl { 
  volumeChanged = output({alias: 'volumeUpdated'}); 
}
Choose one answer
Check answer and explanation

Correct answer: volumeChanged = output({alias: 'volumeUpdated'});

Explanation

The proper configuration involves utilizing the `output` function with an object literal that specifies the `alias` property to rename the event being emitted within the template.

Common trap

Passing the alias as a simple string to the `output` function is syntactically flawed for customizing the output name. Furthermore, using the property name `newAlias` instead of `alias` results in an incorrect implementation.

Source: Angular docs: Custom events with outputs — Customizing output names
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is building a reusable `UserDisplay` component and needs to accept the user's email address. Which naming convention for the `@Input()` property is best practice according to modern Angular guidelines to prevent ambiguity?

import { Component, Input } from '@angular/core';

@Component({
  selector: 'app-user-display',
  standalone: true,
})
export class UserDisplayComponent {
  @Input() userEmail: string = '';
}
Choose one answer
Check answer and explanation

Correct answer: @Input() userEmail: string = '';

Explanation

The choice "@Input() userEmail: string = '';" is correct because it avoids naming the input property after a standard DOM element attribute, thus preventing confusion.

Common trap

The choice "@Input() email: string = '';" is tempting because it is concise, but it risks colliding with native DOM properties. The choice "@Input() inputEmail: string = ''" is incorrect because adding prefixes like 'input' is unnecessary since the component context already defines the property.

Source: Angular docs: Accepting data with input properties — Choosing input names
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is building a service in Angular 22 that needs to format a numeric value according to the user's locale. According to current best practices documented for this framework, what is the recommended approach for achieving locale-aware formatting?

import {inject, Inject} from '@angular/core';
import {formatNumber} from '@angular/common';

@Injectable({ providedIn: 'root' }) 
export class NumberFormatterService {
  private locale = inject(LOCALE_ID);

  formatValue(value: number) {
    return formatNumber(value, this.locale, '1.2-2');
  }
}
Choose one answer
Check answer and explanation

Correct answer: Utilizing the standalone formatting function, such as formatNumber, imported from '@angular/common'.

Explanation

The documentation explicitly advises using the standalone formatting functions, stating: "Use these functions instead of injecting the pipe class."

Common trap

Injecting the pipe class is the older pattern that the documentation advises against. Relying on the template syntax inside a service defeats the purpose of the service.

Source: Angular docs: Pipes — Use formatting functions for built-in pipes
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A component uses `@ViewChildren` to gather references to several child elements. The developer needs to execute a specific side effect immediately whenever the set of referenced elements changes. Which mechanism should the developer utilize?

import { Component, ViewChildren, QueryList } from '@angular/core';

@Component({
  selector: 'app-parent',
  template: `<div><app-child></app-child><app-child></app-child></div>`
})
export class ParentComponent {
  @ViewChildren(ChildComponent) children!: QueryList<ChildComponent>;
  
  ngAfterViewInit() { 
    // Logic here
  }
}
Choose one answer
Check answer and explanation

Correct answer: Subscribe to the `changes` property of the `QueryList` to trigger logic whenever the collection is modified.

Explanation

The correct approach is to "Subscribe to the `changes` property of the `QueryList` to trigger logic whenever the collection is modified," as this is the documented method for reacting to dynamic updates.

Common trap

Calling `toArray()` only captures the list's state at that exact moment, not future changes. Using `map` or `reduce` processes the current data but doesn't set up a listener for future modifications.

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

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is creating a component that extends a base component, which already defines an `@Output` property named `dataUpdated`. To ensure the derived component exposes this event under a different name, `payloadChange`, in its template, how should the `@Component` metadata be configured?

import { Component } from '@angular/core';

@Component({
  selector: 'app-derived',
  template: `...`,
  outputs: ['dataUpdated: payloadChange']
})
export class DerivedComponent extends BaseComponent {} // BaseComponent has @Output() dataUpdated = new EventEmitter<any>()
Choose one answer
Check answer and explanation

Correct answer: outputs: ['dataUpdated: payloadChange']

Explanation

The configuration 'outputs: ['dataUpdated: payloadChange']' correctly maps the inherited output 'dataUpdated' to a new alias 'payloadChange' when using the `outputs` property.

Common trap

Using 'outputs: ['payloadChange']' would only register the alias if the base class already defined an output with that name, which is not the case here. Simply listing 'dataUpdated' would use the original name.

Source: Angular docs: Custom events with outputs — Specify outputs in the `@Component` decorator
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is creating a custom component where data must only be set from the parent, but never read back by the child component's internal logic. Which approach, based on current best practices, is recommended for this scenario?

export class DataInputComponent {
  @Input()
  set configuration(config: any) {
    this._config = config;
  }
  private _config: any;
}
Choose one answer
Check answer and explanation

Correct answer: Implement the input using only a public setter, effectively creating a write-only interface.

Explanation

The correct approach is to implement the input using only a public setter, effectively creating a write-only interface, as demonstrated by the ability to create a write-only input by only defining a public setter.

Common trap

Relying on a standard `@Input()` property does not enforce write-only behavior, and using a getter that throws an error is overly complex and non-standard for this requirement.

Source: Angular docs: Accepting data with input properties — Inputs with getters and setters
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is creating a parent component that renders several instances of a child component. To process all of these child instances once the view is initialized, which decorator and lifecycle hook should the developer utilize?

import { Component, ViewChildren } from '@angular/core';

@Component({ /* ... */ }) 
export class ParentComponent {
  @ViewChildren(ChildComponent) children!: QueryList<ChildComponent>;

  ngAfterViewInit() { /* logic */ }
}
Choose one answer
Check answer and explanation

Correct answer: Employ @ViewChildren() to retrieve a QueryList and process the collection in ngAfterViewInit().

Explanation

The correct approach is to 'Employ @ViewChildren() to retrieve a QueryList and process the collection in ngAfterViewInit()', because the source indicates that '@ViewChildren' creates a QueryList object and results are available in 'ngAfterViewInit'.

Common trap

Using the constructor is incorrect because view queries are not available until after the view is rendered. Relying on ngOnInit() is wrong because the source specifies that view query results become available in 'ngAfterViewInit'.

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

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is creating a reusable component that needs to accept a configuration setting, but they want the consuming template to use a more user-friendly name than the internal TypeScript property name. How should the developer implement this using Angular's input mechanism?

export class ConfigComponent {
  config = input.required({alias: 'userSettings'});
}
Choose one answer
Check answer and explanation

Correct answer: Use the `alias` option within the `input()` function to map the template binding name to the internal property.

Explanation

The recommended method is to 'Use the `alias` option within the `input()` function to map the template binding name to the internal property,' because this mechanism permits the internal property name to be distinct from how it is referenced in the template.

Common trap

The suggestion to 'Define the input property using the `[alias]` attribute directly on the component tag in the consuming template' is flawed because template binding names are established when the component tag is utilized, not through an internal API configuration. Furthermore, 'Override the input property getter in the component class to return the aliased value' introduces logic overriding, which deviates from the intended functionality of input aliasing.

Source: Angular docs: Accepting data with input properties — Input aliases
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is creating a reusable UI element and wants to keep the logic (TypeScript) completely separate from the visual markup (HTML) and styling (CSS). Which configuration approach should they adopt?

@Component({
  selector: 'user-card',
  templateUrl: './user-card.html',
  styleUrl: './user-card.css',
}) 
export class UserCard {}
Choose one answer
Check answer and explanation

Correct answer: Use templateUrl and styleUrl properties to reference external files for presentation and styling.

Explanation

The developer should 'Use templateUrl and styleUrl properties to reference external files for presentation and styling.' This explicitly allows for separating the concerns of presentation from behavior.

Common trap

Defining styles inline only affects elements within that component's template, and placing styles in the class body is not a valid mechanism for styling components.

Source: Angular docs: guide/components/anatomy-of-components — guide/components/anatomy-of-components
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is creating a reusable UI widget and needs to notify its parent component when a specific internal action occurs, such as a 'dataSaved' event. Which mechanism should they use to expose this event to the parent component?

export class DataWidgetComponent {
  dataSaved = output<void>();
  saveData() {
    // ... logic to save data
    this.dataSaved.emit();
  }
}
Choose one answer
Check answer and explanation

Correct answer: Define a property using the `output` function and call `.emit()` on it when the event fires.

Explanation

Defining a property using the `output` function and call `.emit()` on it when the event fires is the prescribed way to raise custom events in Angular components.

Common trap

Declaring a public method is not how Angular components expose custom events, and using `@Input()` is for receiving data, not emitting events.

Source: Angular docs: Custom events with outputs — Custom events with outputs
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A front-end developer is displaying a user's purchase date in a component. They want the date to automatically format according to the user's regional settings (e.g., MM/DD/YYYY for the US). Which syntax should they use in the template?

<p>Date: {{ purchaseDate | date }}</p>
Choose one answer
Check answer and explanation

Correct answer: <p>Date: {{ purchaseDate | date }}</p>

Explanation

The appropriate syntax involves utilizing the built-in 'date' pipe, which guarantees that the output conforms to the user's locale settings, as illustrated by the example displaying US formatting.

Common trap

The syntax that employs a non-existent pipe name, and the syntax that tries to invoke a method directly on the bound property, circumventing Angular's transformation pipeline.

Source: Angular docs: Pipes — Overview
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A frontend engineer needs to display a timestamp using the `DatePipe`, first specifying the desired time format and then overriding the default timezone setting. Which template syntax correctly achieves this configuration?

<p>Time: {{ eventTime | date: 'HH:mm' : 'America/Los_Angeles' }}</p>
Choose one answer
Check answer and explanation

Correct answer: <p>Time: {{ eventTime | date: 'HH:mm' : 'America/Los_Angeles' }}</p>

Explanation

The proper method for supplying several arguments to a pipe involves using colons as separators, as shown in the example "{{ scheduledOn | date: 'hh:mm' : 'UTC' }}".

Common trap

The syntax employing function-call notation is invalid for pipe parameterization. Furthermore, attempting to sequence pipes instead of passing multiple arguments to a single pipe is incorrect.

Source: Angular docs: Pipes — Passing parameters to pipes
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is implementing a bidirectional synchronization feature between a parent component holding a state variable and a child component managing that state. Based on the provided pattern, what is the required mechanism for the parent to receive updates initiated by the child?

app-counter [(count)]="initialCount"
Choose one answer
Check answer and explanation

Correct answer: The parent binds using the two-way binding syntax `[(count)]` on the child selector, leveraging the child's `model()` signal.

Explanation

The correct implementation involves applying the two-way binding syntax, such as `[(count)]`, directly to the child component's selector. This functionality is enabled because the child component utilizes the `model()` signal for its property.

Common trap

The pattern described in the option stating that the child component must expose a specific output event for the parent to subscribe to represents a standard one-way data flow mechanism, which is not the technique employed in this scenario. Furthermore, the suggestion that the child component should employ the `ngModel` API on its property is generally associated with form control elements.

Source: Angular docs: Two-way binding — Two-way binding between components
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is implementing a custom event handler in Angular to introduce a debouncing mechanism for user input. To make this custom functionality available globally across the application's templates and host bindings, what is the required setup step?

Choose one answer
Check answer and explanation

Correct answer: Provide the custom plugin class against the `EVENT_MANAGER_PLUGINS` token in the application's bootstrapping configuration.

Explanation

The source explicitly shows that the custom plugin must be registered by providing it against the `EVENT_MANAGER_PLUGINS` token during application bootstrapping.

Common trap

Defining a custom directive is an alternative approach but does not fulfill the requirement of creating a system-wide event plugin as described. Relying solely on an `@Input()` property limits the functionality to only the component that receives the input.

Source: Angular docs: Adding event listeners — Implementing Event Plugin
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is implementing a custom lifecycle hook within a component. Based on the documentation, what is the fundamental constraint regarding state modifications during the component traversal phase?

import { Component } from '@angular/core';

@Component({
  selector: 'app-data-handler',
  standalone: true,
  template: '<div>Loading...</div>'
})
export class DataHandlerComponent {
  ngOnInit() {
    // Logic here
  }
}
Choose one answer
Check answer and explanation

Correct answer: They should always avoid modifying component state during the traversal, as this can interfere with Angular's update checks.

Explanation

The appropriate guideline is to refrain from altering component state while iterating through the structure, because such modifications risk disrupting Angular's update verification process. This aligns with the documentation's statement that the traversal visits each component only one time.

Common trap

The suggestion that operations must be exclusively synchronous is inaccurate, as the documentation does not impose such a limitation. Furthermore, the advice permitting state changes, contingent upon batching and occurring after the component's initialization hook, contradicts the source's explicit caution against subsequent state modifications during the traversal.

Source: Angular docs: Component Lifecycle — Component Lifecycle
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer implements `ngOnChanges` in a component that receives an input property. If this component is initialized and the input property is set immediately upon creation, when will the developer's logic inside `ngOnChanges` execute relative to the component's setup lifecycle?

import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';

@Component({ selector: 'app-profile', standalone: true }) 
export class ProfileComponent implements OnChanges {
  @Input({ required: true }) userId!: number;

  ngOnChanges(changes: SimpleChanges): void {
    // Logic here
  }
}
Choose one answer
Check answer and explanation

Correct answer: It runs before the component's template is rendered, and is executed even for the initial input value.

Explanation

The appropriate mechanism is the one that executes prior to the component's template rendering and is triggered even when the input value is set for the first time. This aligns with documentation indicating that `ngOnChanges` fires before the template check, and that the initial invocation of `ngOnChanges` happens before `ngOnInit` completes its setup.

Common trap

The assertion that the execution occurs after `ngOnInit` finishes is inaccurate because the documentation specifies that `ngOnChanges` precedes the template check, which happens before `ngOnInit` is fully executed. Furthermore, the claim that it only triggers upon a transition between distinct input states is false, as the documentation confirms the initial execution occurs during setup.

Source: Angular docs: Component Lifecycle — ngOnChanges
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer needs to create a custom Angular pipe that converts a user's full name into a specific format within a template. To correctly define this pipe, what fundamental structural requirements must the TypeScript class satisfy?

import {Pipe, PipeTransform} from '@angular/core';
@Pipe({name: 'nameFormatter'}) export class NameFormatterPipe implements PipeTransform {
  transform(value: string): string { return value; }
}
Choose one answer
Check answer and explanation

Correct answer: It must implement the PipeTransform interface and include a method named 'transform' to handle the value manipulation.

Explanation

The required implementation necessitates that the class adheres to the 'PipeTransform interface' and contains a method named 'transform' for value manipulation.

Common trap

The suggestion to use a public method called 'apply' instead of 'transform' is incorrect, and the idea of extending a base class instead of implementing an interface is also flawed.

Source: Angular docs: Pipes — Creating custom pipes
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer needs a custom pipe to aggregate data from an array property within a component's view. Since the input array changes frequently but its contents might not change in a way Angular's standard change detection can track easily, which configuration must the pipe employ to ensure it recalculates upon every change detection cycle?

import {Pipe, PipeTransform} from '@angular/core';

@Pipe({ name: 'dataAggregatorImpure', pure: false }) 
export class DataAggregatorPipe implements PipeTransform { transform(data: any[]): any { return data.reduce((acc, item) => acc + item.value, 0); } }
Choose one answer
Check answer and explanation

Correct answer: The pipe must be explicitly declared with `pure: false` in its `@Pipe` decorator.

Explanation

The pipe must be explicitly declared with `pure: false` in its `@Pipe` decorator, as this configuration tells Angular to bypass standard purity checks and re-execute the transformation function.

Common trap

Using `OnPush` on the component does not automatically force the pipe to run; the pipe's purity setting controls its execution frequency. Wrapping the input in a Signal is a modern Angular pattern but is not the direct mechanism described for making a pipe impure.

Source: Angular docs: Pipes — Detecting change within arrays or objects
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer needs to dynamically set the 'aria-label' on a custom button component based on the output of a method, `getStatusDescription()`. Which binding mechanism should they use to ensure the text is correctly applied and automatically removed if the method returns nothing?

<button type="button" [aria-label]="getStatusDescription()">Click Me</button>
Choose one answer
Check answer and explanation

Correct answer: Use property binding: `<button [aria-label]="getStatusDescription()">`

Explanation

The correct approach is using property binding (`[aria-label]`) because Angular is designed to write the string value to the element’s `aria-label` attribute and remove it when the bound value is `null` or `undefined`.

Common trap

Interpolation (`{{ }}`) only outputs text content, not attribute values, and attribute binding treats the method call as a static string.

Source: Angular docs: Binding dynamic text, properties and attributes — ARIA attributes
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer needs to interact with an element rendered inside their component's template, such as a third-party charting library instance, immediately after Angular has finished rendering that element. Which lifecycle hook is the most appropriate place to perform this initialization logic?

import { Component, AfterViewInit } from '@angular/core';

@Component({
  selector: 'app-chart',
  standalone: true,
  template: `<div><canvas #chartCanvas></canvas></div>`
})
export class ChartComponent implements AfterViewInit {
  ngAfterViewInit() {
    // Initialization logic goes here
  }
}
Choose one answer
Check answer and explanation

Correct answer: ngAfterViewInit

Explanation

The correct choice is "ngAfterViewInit" because this hook executes only after the component's view and all its child views have been fully initialized, allowing access to view queries.

Common trap

Using "ngOnInit" is incorrect because it runs before the component's view elements are available for inspection. "ngOnChanges" is for reacting to input property value changes, not for initial view setup.

Source: Angular docs: Component Lifecycle — ngAfterViewInit
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.I · Angular 22 practice question

A developer is working on a custom host component that needs to pass the specific dependency injection context of a projected child element to an outlet template. Which approach, using `contentChild`, allows them to retrieve the injector associated with that projected element?

export class CustomHost { 
  childInjector = contentChild(TargetDirective, {read: Injector}); 
}
Choose one answer
Check answer and explanation

Correct answer: Using `contentChild(TargetDirective, {read: Injector})` to capture the injector from the element matching `TargetDirective`.

Explanation

The official documentation indicates that supplying `Injector` within the `read` property enables the retrieval of the injector associated with the element that matches the query. This concept is illustrated by the example showing the use of `contentChild(TemplateRef)` alongside `innerInjector = viewChild('inner', {read: Injector})`.

Common trap

The assertion that `viewChild` is the appropriate method for querying projected content is flawed, as is the approach of manually navigating the DOM, which circumvents Angular's built-in structured querying capabilities.

Source: Angular docs: Referencing component children with queries — Reading specific values from an element's injector
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


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

Open this question on its own page


Back to all topics