是否存在与Angular 1的$ interpolate相当的Angular 2?我想要一个字符串和一个对象,并能够用对象中的值替换字符串中的标记。
例如:
let myTemplateStr = "Hello {{user.name}}, you are {{user.age.years}} years old"
//use the Angular2 equivalent of interpolate
let myTemplateCompiled = Angular2.Interpolate(myTemplateStr, {
user: {
name: "bob",
age: {
years: 10
}
}})
//myTemplateCompiled ends up becoming "Hello bob, you are 10 years old"
我可以写的东西会为我做到这一点,但我更愿意使用一个内置的角度的方式,如果可能的。
编辑:
我应该提到的是,插值需要能够与字符串变量发生。我知道typescript/es6对文字字符串有反向插值,但是我需要插入存储在变量中的字符串模板。也许有一种方法可以在我不知道的变量中使用为插入字符串模板插入内置的typescript?
嗨,感谢您的回答,我忘了提,我需要插值从发生变量。我现在添加了一个编辑解释。也许有一种方法可以使用变量进行打字稿插值? – tt9