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
TypeScript - Number toString() This method returns a string representing the specified object. The toString() method parses its first argument, and attempts to return a string representation in the specified radix (base).
The toString() method in Javascript is used with a number and converts the number to a string. It is used to return a string representing the specified Number object. The toString() method is used with a number num as shown in the above syntax using the '. ' operator.
The toString() method is a built-in method of the JavaScript Number object that allows you to convert any number type value into its string type representation.
you can use ''+your number
let num:number=3;
let numTxt:string=''+number;
Integer to string is as simple as calling .toString();
As @GünterZöchbauer said TypeScript has the same type coercion as JS, so numbers are automatically converted to strings when used in a string context
So no problem will occur same as Javascript, you can use number as string.
If you want you can do it like this so :
let num = 3;//number
let stringForm = num.toString();
console.log(stringForm);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With