Ilja
Ilja

Reputation: 46479

Angular difference between ${ value } and {{ value }}

I've been reading tutorials on Angular and some people seem to be using following syntax within their templates ${ value } it seems to produce similar value as simply using {{ value }} so I started wondering why add the dollar sign? Is this done for some semantics or does it actually have its functionality?

Upvotes: 8

Views: 3537

Answers (2)

Thierry Templier
Thierry Templier

Reputation: 202216

To complete what Günter said, the ${someVar} corresponds to the string interpolation feature of ES6. This can be used within strings defined between the charater ` (back-tick). This also allows to define string on several lines.

Here is a sample

let someVar = '10';
let someString = `The value of someVar is ${someVar}`;

It's something that can be used outside Angular2 with ES6.

See this link for more details: https://developers.google.com/web/updates/2015/01/ES6-Template-Strings.

Hope it helps you, Thierry

Upvotes: 4

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657496

${someVar} is string interpolation from TS and is applied before the template is processed by angular. {{someVar}} is Angular template binding expression.

Upvotes: 5

Related Questions