翻译时以Angular J的方式显示样式标签



这是我的控制器文件

$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

任何指针?

我假设您正在使用sanitize策略来逃脱:

$translateProvider.useSanitizeValueStrategy('sanitize');

它使用$sanitize服务,因此样式属性将被此服务剥离(为了覆盖此服务,您需要更改angular-sanitize.js的源代码,但我不建议这样做)。作为在这里的解决方法 - 您需要使用class属性(因为类属性未用$sanitize剥离),例如class="red",并设置.red { color:red; }等适当的CSS样式。

示例此处。

使用

<span style="color:red">

不是

<span style=color:red>

最新更新