Skip to main content

Property Binding

Property binding in Angular lets you set values for child elements' DOM properties or child Angular components inputs, using the [property] syntax.

In opposition to interpolation, property binding can set values for properties that are not strings.

Exampleโ€‹

@Component({
selector: 'mc-logo',
template: `<img [src]="logoUri" [alt]="name" width="64" height="64" />`,
})
export class Logo {
readonly logoUri = 'https://marmicode.io/assets/logo.svg';
readonly name = 'Marmicode';
}

Here, [src]="logoUri" and [alt]="name" are property bindings. Angular will keep the image element properties in sync with the logoUri and name properties.

Why use property binding?โ€‹

  • Any value type: Bind booleans, numbers, or objects โ€” not just strings. e.g. [disabled]="isDisabled"
  • Overrides interpolation: Property binding takes precedence if both are used.
Pragmatic Angular Testing
๐Ÿ‘จ๐Ÿปโ€๐Ÿณ Let's cook some tests โ†’

๐Ÿ’ฐ 80โ‚ฌ ยท 170โ‚ฌ ยท Lifetime access

Learn how to write reliable tests that survive upgrades and refactorings.