简体   繁体   English

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

[英]Angular translate service: HTML tags in string

I have an KEY which contains a string with a HTML tag: Foo <strong>bar</strong> and I'm using the angular translate service: 我有一个KEY ,其中包含带有HTML标签的字符串: Foo <strong>bar</strong>并且我正在使用角度翻译服务:

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

As output I get Foo <strong>bar</strong> , but I want to get 'Foo bar '. 作为输出,我得到Foo <strong>bar</strong> ,但是我想得到'Foo bar '。 Is there are way to get this with the translate service? 有没有办法通过翻译服务来做到这一点?

I already set the sanitize strategy to sanitize , but even this does not help. 我已经设置了清理策略以进行sanitize ,但是即使这样做也无济于事。 I know that it works with the translate directive but it doesn't fit to my use case. 我知道它可以与translate指令一起使用,但是不适合我的用例。

您可以使用ngBindHtml指令:

<div ng-bind-html="text"></div>

You can also use $translateProvider.useSanitizeValueStrategy(param); 您还可以使用$translateProvider.useSanitizeValueStrategy(param);

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

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

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