Interpolation in strings made using backtick operator
{{ foo }}
will be handled by the template engine of Angular
, binding the foo property defined in your class.
${ bar }
will be handled by the Javascript string interpolation
, which, while rendering, have no clue of what is the property bar
of your object.
This is something closely related to how Angular
work, this is not related to typescript
or anything else. You can still use ${}
if you are not in your Angular
project, or not in the template.
For example, something like this should work, since the expression is evaluated before being returned, and is not dependant of the template engine:
public getUsername(): string {
let username = 'test';
return `Hi ${username}`;
}
${}
it is a string interpolation to display a value of string between typescript code.
And {{}}
is interpolation to display the content in HTML template.