Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String intrapolation in Angular 2.0

I have a string like {name} is my name. Greeting {sender}

is there some module in angualar 2.0, so that i can do something like string.format() as we do in C#?

I know this can be done using vanila js custom method, but i want to know is there any module inside angular 2 to handle this. They use interpolation in template binding so how to do that with a normal string

like image 212
Dinkar Thakur Avatar asked Mar 11 '23 03:03

Dinkar Thakur


1 Answers

Check ES6 Template literals. It enables multi-line strings and string interpolation.

Example:

var name = 'John',
    age = 19;

console.log(`${name} is my name. I'm ${age}.`); 

// => John is my name. I'm 19.

TypeScript from version 1.4 supports ES6 Template literals and can compile them down to ES3/ES5 expressions.

like image 59
seidme Avatar answered Mar 19 '23 02:03

seidme