String Interpolation

  • String interpolation is used to display dynamic data on HTML template
  • It facilitates you to make changes on component.ts file and fetch data from there to HTML template
  • Let us create a new Angular project using Angular CLI
  • And update the app.component.html and app.component.ts as per below

Example 1

app.component.ts

app.component.html

Output :

Example 2

In app.component.ts file we add two new data members userName and greetingMsg, values of these two variables will be displayed on the html template

We add double curly braces and add the newly created data member names in it so that the data is fetched dynamically from the data members itself.

Output of the above code will look like below :

Leave a Comment