【问题标题】:translate attribute values with ngx-translate angular使用 ngx-translate angular 转换属性值
【发布时间】:2019-04-12 07:47:08
【问题描述】:

我正在尝试将 ngx-translate 用于属性值,例如 p消息文本, p 列标题, p-tabPanel 标题

<p-message text="text"></p-message>

<p-column header="text"></p-column>

<p-tabPanel header="text">

我尝试了以下方法,但它不起作用:

<p-tabPanel header="'key' | translate">

<p-tabPanel header="{{'key' | translate}}">

<p-tabPanel [attr.header]="'key' | translate">

有没有办法使用 ngx-translate 来处理这些?

【问题讨论】:

    标签: angular ngx-translate


    【解决方案1】:

    以下解决方案有效:

     <p-tabPanel header="{{'key' | translate}}">
    

    但是在需要的模块中导入 TranslateModule 时要非常小心。

    【讨论】:

      【解决方案2】:

      来自this github issue

      <img src="image.jpg" [attr.alt]="'key' | translate"> or like this:
      <input placeholder="{{'key' | translate}}">
      

      【讨论】:

      • 感谢您的回复@Ferenc。我在这种情况下尝试了这个模型,但它不起作用:
      • 这很奇怪。 this fiddle 有帮助吗?
      • 看到这个小提琴后,我意识到问题在于没有在包含组件的正确模块中导入 TranslateModule。因此,感谢您的帮助和时间。以下工作:
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-27
      • 1970-01-01
      相关资源
      最近更新 更多