0 day streak
javascript / beginner
Snippet

Dynamic Attributes with Property Binding

Property binding uses square brackets to set an element's property to a value from the component's TypeScript class.

snippet.js
javascript
1
2
<!-- component.html -->
<img [src]="imageUrl" [alt]="imageDescription">
angular
Breakdown
1
[src]
The square brackets tell Angular to evaluate the right side as a TypeScript expression rather than a plain string.
2
imageUrl
The property in your class containing the URL of the image.