如何使用 angular-translate 翻译属性的内容

How to translate the content of an attribute with angular-translate

在我的 mongo 模式中,我有一个预定义类型的枚举:

let MeterSchema = new Schema({
[...]
type: {
    type: String,
    enum: ['Prepayment', 'TimeOfDay', 'PowerExport']
},
[...]
}

我想要的是在我的 angular 视图中显示这个用 i18n 文件国际化的值。 我查看了 angular 翻译 (https://angular-translate.github.io/docs/#/guide/06_variable-replacement) 的 Variale 替换,但无法弄清楚如何正确地使用它。

目前我是这样翻译的:

查看

<div class="md-summary">{{vm.getMeterType(meter) | translate}}</div>

控制器

public getMeterType(meter): String {
    return 'app.masterData.meters.type.' + meter.type;
}

但我认为必须有更好的方法。

答案其实很简单:

<div class="md-summary">{{'app.masterData.meters.type.' + meter.type | translate}}</div>

我不知道为什么我一开始没有使用字符串连接。