Inject a translated string as an input in an angular 5 component

十年热恋 提交于 2020-03-05 05:07:41

问题


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

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

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


回答1:


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



来源:https://stackoverflow.com/questions/49782701/inject-a-translated-string-as-an-input-in-an-angular-5-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!