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?
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}`;
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