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'});
}
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.