简体   繁体   English

ngx-translate:如何“翻译” html属性?

[英]ngx-translate: how to 'translate' a html attribute?

I've implemented ngx-translate in my Angular-Cli app and works fine when I do something like: 我已经在Angular-Cli应用程序中实现了ngx-translate,并且在执行以下操作时可以正常工作:

<div>{{ 'some.value' | translate }}</div>

But how can I go about translating an attribute of an HTML component? 但是,如何翻译HTML组件的属性? Something like: 就像是:

<div data-text="{{ 'some.value' | translate }}"></div>

(this code above doesn't work) (以上代码无效)

Thanks in advance for any help provided... 预先感谢您提供的任何帮助...

JB JB

What error are you getting? 你遇到了什么错误?

The code, as it appears, should work, but there's also another option to try: 看上去的代码应该可以工作,但是还有另一种方法可以尝试:

<div [data-text]="'some.value' | translate"></div>

Off the top of my head, I'd guess you're getting an error like 'data-text' is not a property of <div> , in which case it's not an ngx-translate issue but a missing imports in your .component.ts file that could add the missing attribute. 关闭我的头顶,我猜你得到这样的错误'data-text' is not a property of <div> ,在这种情况下,它不是一个NGX-翻译的问题,而是缺少imports.component.ts文件可能会添加缺少的属性。

这应该工作

<div [attr.my-attribute]="'value.to.translate' | translate"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM