角度翻译服务:字符串中的 HTML 标签

Angular translate service: HTML tags in string

本文关键字:HTML 标签 字符串 翻译服务      更新时间:2023-09-26

我有一个KEY,其中包含一个带有HTML标签的字符串:Foo <strong>bar</strong>,我正在使用角度翻译服务:

$translate('KEY').then(function(text) {
    $scope.text = text;
});

作为输出,我得到Foo <strong>bar</strong>,但我想得到"Foo bar"。有没有办法通过翻译服务获得这个?

我已经将消毒策略设置为sanitize,但即使这样也无济于事。我知道它适用于翻译指令,但它不适合我的用例。

您可以使用 ngBindHtml 指令:

<div ng-bind-html="text"></div>
您也可以

使用$translateProvider.useSanitizeValueStrategy(param);

https://angular-translate.github.io/docs/#/guide/19_security