What is Angular's template syntax used for displaying dynamic values on the page?
Short answer
You use double curly braces, called interpolation, to display the value of a property directly inside your HTML template. Angular automatically keeps this displayed value in sync whenever the underlying property changes.
Advertisement
AModel answer
You use double curly braces, called interpolation, to display the value of a property directly inside your HTML template. Angular automatically keeps this displayed value in sync whenever the underlying property changes.
@Component({
selector: 'app-price',
template: `<p>Total: {{ price * quantity }}</p>`
})
export class PriceComponent {
price = 10;
quantity = 3;
}Real-world example
A shopping cart component uses interpolation to calculate and display the total price of an item directly inside the template, updating automatically whenever the quantity changes.
Likely follow-ups
- Can you call a function inside interpolation, not just a simple property?
- What happens if the value inside interpolation is null or undefined?
Related topics