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

Angular translate service: HTML tags in string

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

$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