Search code examples
angulartypescriptangular2-template

How to convert number to string inside angular 2 component:


Inside the component i have

export class AppComponent implements OnInit {


public errorMsg :number =10 ;

public doughnutChartOptions: any = {
 cutoutPercentage: 85,
  elements: {
    center: {
      text: this.errorMsg + ' Energy produced in the Energy',
      fontColor: '#fff',
      fontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
      fontSize: 24,
      fontStyle: 'normal'
    }
  }
};

}

  text: this.errorMsg + ' some thing',

This is a property accepted string , so here i have to pass the number to string , How to do that in angular4,typescript 2.5


Solution

  • Pls try

    text:  `${this.errorMsg} Energy produced in the Energy`,
    

    NB: Use `` (back-ticks) , instead of '' (apostrophe), to get your value.