NG.II · Angular 22 practice question

A state management service exposes a signal derived from an internal writable signal using `.asReadonly()`. A component then attempts to call `.set()` on the exposed signal. What will be the result?

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

class StateService {
  private _data = signal([1, 2]);
  public data = this._data.asReadonly();
}

// In component:
const service = new StateService();
service.data.set([3, 4]); // Attempt to modify
Choose one answer
Check answer and explanation

Correct answer: The modification will fail silently because the readonly wrapper prevents direct mutation methods like .set() or .update().

Explanation

The modification will fail silently because the readonly wrapper prevents direct mutation methods like .set() or .update().

Common trap

The assertion that 'the modification will succeed because the signal object itself is mutable' is misleading, as the readonly wrapper enforces immutability on the API exposed.

Source: Angular docs: guide/signals/overview — Writable signals
Checked against the cited text on 2026-11-25.

Report an error in this question