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