String Interpolation in Angular 8

String Interpolation in Angular 8 is a one-way data-binding technique that is used to transfer the data from a TypeScript code to an HTML template (view). It uses the template expression in double curly braces to display the data from the component to the view. String interpolation adds the value of a property from the component to the HTML template view.

Syntax:

{{ component_property }}

Approach: 

  • Define a property in the app.component.ts file containing some string value.
  • In the app.component.html file, bind the value of that property by calling the property name in double curly braces {{ property_name }}.

Example 1: 

  • app.component.html



    HTML

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <h1>
      {{ title }}
    </h1>

    chevron_right

    
    

  • app.component.ts

    Javascript

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    import { Component } from '@angular/core';    
    @Component({    
      selector: 'app-root',    
      templateUrl: './app.component.html',    
      styleUrls: ['./app.component.css']    
    })    
    export class AppComponent {   
      title = "GeeksforGeeks";
    }

    chevron_right

    
    

Output:

Example 2:

  • app.component.html

    HTML

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <h1 [style.color] = "'green'" 
        [style.text-align] = "'center'" >
        {{ title }} : {{ about }}
    </h1>

    chevron_right

    
    

  • app.component.ts

    Javascript

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    import { Component } from '@angular/core';    
    @Component({    
      selector: 'app-root',    
      templateUrl: './app.component.html',    
      styleUrls: ['./app.component.css']    
    })    
    export class AppComponent {   
      title = "GeeksforGeeks";
      about = "Computer Science Portal for Geeks";
    }

    chevron_right

    
    

Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.