Angular

Last Updated: 6/15/2023

Property Binding

  • String Interpolation is a syntatically sugar. When Angular compiles the template it is converted into property binding
  • Use string interpolation when rendering dynamic values/text between heading, para, div, span
  • Property binding is binding of the property of DOM element to field or property of the component
  • Whenever the value of field/property changes the property of DOM is updated
  • Property binding is one way binding from component to view, any changes from dom are not reflected in the component

String Interpolation

	<h2>{{ title }}</h2>
	<img src="{{imageUrl}}" />

Property Binding

	<h2 [textContent]="title"></h2>
	<img [src]="imageUrl" />
  • The brackets tell Angular to evaluate the template expression.
  • If you omit the brackets, Angular treats the string as a constant and initializes the target property with that string. It does not evaluate the string!