将翻译后的字符串作为角度5分量的输入注入 [英] Inject a translated string as an input in an angular 5 component

查看:113
本文介绍了将翻译后的字符串作为角度5分量的输入注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个角度分量模板,我想将title作为@Input()注入其中,显示为:

I have an angular component template I want to inject title as an @Input() into, to be displayed as:

  <div class="title" >
    {{ title }}
  </div>

如何使用ng2-translate的管道将翻译后的title注入父组件,如下所示:

How do I inject the translated title into the parent component using ng2-translate's pipe, like so:

<title-component
    [title]="{{ 'KEY' | translate }}"
></title-component>

我想将翻译后的字符串动态传递给子组件,但我希望避免将翻译服务注入到组件的构造函数中,并尽可能将所有内容保留在模板中.谢谢

I want to pass the translated string dynamically to the child component, but I'd prefer to avoid injecting the translate service into the component's constructor and keep everything in the template, if possible. Thanks

推荐答案

{{}},因此删除这些应该可以解决您的问题

{{}} are not required in inputs, so removing those should solve your issue

这篇关于将翻译后的字符串作为角度5分量的输入注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆