【问题标题】:Is it possible use ngx-translate with Teradata Covalent Dynamic form?是否可以将 ngx-translate 与 Teradata Covalent Dynamic 形式一起使用?
【发布时间】:2018-05-29 13:21:54
【问题描述】:

我想知道是否可以将 ngx-translate 与共价动态表单一起使用。 我的模板如下所示:

<td-dynamic-forms [elements]="dataElements">
</td-dynamic-forms>

我的 dataElements 数组:

this.dataElements = [
  {
    'name': 'name',
    'label': 'NAME',
    'type': 'text',
    'disabled': true,
    'required': true,
    'default': this.application ? this.application.name : ''
  },
  {
    'name': 'description',
    'label': 'DESCRIPTION',
    'type': 'textarea',
    'required': false,
    'default': this.application ? this.application.description : ''
  },
];

我想使用 ngx-translate 翻译标签。我在其他常规表单中使用相同,但我想知道是否可以在动态表单中使用翻译。

【问题讨论】:

    标签: angular ngx-translate teradata-covalent


    【解决方案1】:

    您可以在对象中使用 getter 定义 Label 字段,并在方法中执行您需要的操作。创建动态表单时,它会调用 getter 标签并接收本地化值。

    要访问翻译服务,您可以将实例作为新字段添加到对象中,并在 label() 方法中使用 this.translateService 访问它。

        this.dataElements = [
          {
            'name': 'name',
            'type': 'text',
            'disabled': true,
            'required': true,
            'default': this.application ? this.application.name : '',
            'translateService': this.translateService, //add translation service instance to the object 
             get label() {
                  return this.translateService.get("NAME").value;//get traslation by key.
                }
          },
          {
            'name': 'description',
            'type': 'textarea',
            'required': false,
            'default': this.application ? this.application.description : '',
            'translateService': this.translateService,
             get label() {
                  return this.translateService.get("DESCRIPTION").value;
                }
          },
        ];
    

    【讨论】:

      猜你喜欢
      • 2018-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-06
      • 2020-09-01
      • 2019-11-17
      相关资源
      最近更新 更多