
Interpolation syntactic sugar over property binding
We concluded the section on interpolations by describing interpolation as syntactical sugar over property binding. The intent was to highlight how both can be used interchangeably. The interpolation syntax is terser than property binding and hence is very useful. This is how Angular interprets an interpolation:
<h3>Main heading - {{heading}}</h3>
<h3 [text-content]="' Main heading - '+ heading"></h3>
Angular translates the interpolation in the first statement into the textContent property binding (second statement).
Interpolation can be used in more places than you can imagine. The following example contrasts the same binding using interpolation and property binding:
<img [src]="'/assets/images/' + currentExercise.exercise.image" />
<img src="/assets/images/{{currentExercise.exercise.image}}" /> // interpolation on attribute
<span [text-content]="helpText"></span>
<span>{{helpText}}</span>
While property binding (and interpolations) makes it easy for us to bind any expression to the target property, we should be careful with the expression we use. Angular's change detection system will evaluate your expression binding multiple times during the life cycle of the application, as long as our component is alive. Therefore, while binding an expression to a property target, keep these two guidelines in mind.