Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of `${}` in Angular? [duplicate]

I sometimes see this kind of syntax inside backticks in TypeScript component files in Angular projects:

<div ${selector} [inDemo]="false" [config]="demoConfig">Demo Content</div>

Can somebody explain me this specific attribute ${}?

How does it work and when should I use it?

like image 547
ivanasetiawan Avatar asked Nov 07 '25 14:11

ivanasetiawan


1 Answers

It's called template literals, It is a feature of ECMASCRIPT6 (ECMASCRIPT2015)

Without using it, you can concat a string with some variables by:

var a = 10, b = 15;
var string = "a equals to " + a + " and b equals to " + b;

By using template litteral, it will be simpler:

var a = 10, b = 15;
var string = `a equals to ${a} and b equals to ${b}`;
like image 143
Faly Avatar answered Nov 09 '25 10:11

Faly