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>
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.