翻译时在 angular js 中显示样式标签

Display style tag in angular js while translation

这是我的控制器文件,其中

$scope.htmlCompanyFromScope = '<span style=color:red>Micro</span>';
$scope.htmlTagFromScope = "MicroTag";

我的 *.resx 文件包含

 TranslationValue = "{{htmlCompany}} tag is {{htmlTag}}"

在我的 HTML 中,我定义了以下内容:

 <span translate="TranslationValue " translate-values="{htmlCompany: htmlCompanyFromScope , htmlTag: htmlTagFromScope}"></span>

但最终,风格并没有得到尊重。 显示类似

的内容

微标签为MicroTag

有什么指点吗?

使用

<span style="color:red">

没有

<span style=color:red>

我假设您正在使用 sanitize 转义策略,例如:

$translateProvider.useSanitizeValueStrategy('sanitize');

It uses $sanitize service, so style attributes will get stripped by this service(要覆盖它,您需要更改 angular-sanitize.js 的源代码,但我不建议这样做)。作为这里的解决方法 - 您需要使用 class 属性(因为 class 属性未被 $sanitize 删除),例如 class="red" 并设置适当的 css 样式,例如 .red { color:red; }

示例 here.