【问题标题】:How to translate the content of an attribute with angular-translate如何使用 angular-translate 翻译属性的内容
【发布时间】:2016-11-30 19:33:54
【问题描述】:

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

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

我想要的是在我的角度视图上显示这个用 i18n 文件国际化的值。 我查看了 angular translate (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;
}

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

【问题讨论】:

    标签: angularjs mongodb internationalization angular-translate


    【解决方案1】:

    答案其实很简单:

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

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

    【讨论】:

      猜你喜欢
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 2018-05-05
      • 1970-01-01
      • 2016-05-15
      • 1970-01-01
      • 1970-01-01
      • 2015-08-31
      相关资源
      最近更新 更多