在我的Angular 4应用程序中,我有一个组件,它带有一个字符串输入:
<app-my-component [myInput]="'some string value'"></app-my-component>
在某些情况下,我需要在字符串中传递一个变量,例如:
<app-my-component [myInput]="'My name is ' + name + '!'"></app-my-component>
如果我可以使用ES6模板字面量(又称为模板字符串或反引号字符串)就好了:
<app-my-component [myInput]="`My name is ${name}!`"></app-my-component>
但是它并不起作用:
未捕获的错误:模板解析错误: 解析器错误:意外记号Lexer Error:在表达式中第1列的意外字符[`]
实现正确方式是什么?