Property binding lets you set HTML element properties from your component data. It keeps your page dynamic and interactive without extra code.
Property binding with square brackets in Angular
<element [property]="componentValue"></element>[] around the property name to bind it to a component variable or expression.src property of the image to the imageUrl variable from the component.<img [src]="imageUrl">isDisabled is true in the component.<button [disabled]="isDisabled">Click me</button>userName from the component.<input [value]="userName">This component shows a greeting with the user name. The input box uses property binding to set its value from userName. When you type, it updates userName. The submit button is disabled if userName is empty.
It uses property binding with square brackets to keep the input and button properties in sync with the component data.
import { Component } from '@angular/core'; @Component({ selector: 'app-root', template: ` <h1>Welcome, {{ userName }}!</h1> <input [value]="userName" (input)="userName = $event.target.value" aria-label="User name input"> <button [disabled]="!userName">Submit</button> ` }) export class AppComponent { userName = 'Alice'; }
Property binding updates the DOM property, not the HTML attribute. This is important for elements like input where the property controls the displayed value.
Always use property binding for dynamic values instead of string interpolation inside attributes to avoid unexpected behavior.
Use aria-label or other accessibility attributes to keep your UI accessible.
Property binding with square brackets connects component data to element properties.
It keeps the UI updated automatically when data changes.
Use it for dynamic attributes like src, disabled, and value.