String interpolation expressions enable interpolating (surprise!) the result of an expression with text. The best way to demonstrate this capability is with an example. Below are two span elements with data-bound textcontent :
<span textcontent.bind="'Hello' + firstName"></span>
<span>Hello ${firstName}</span>
The first span uses the bind command. The second uses string interpolation. The interpolated version is much easier to read and easy to remember because the syntax matches the
template literal syntax standardized in
ES2015
.
String interpolation can be used within HTML attributes as an alternative to to-view
binding. By default, the mode of an interpolation binding is to-view
and the result of the expression is always coerced to a string. Results that are null
or undefined
will result in an empty string.