2017-04-19 62 views
1

进出口使用"angular-translate": "^2.15.1"$translateProvider.useSanitizeValueStrategy('sce')

在我的控制,我需要一个翻译字符串值传递给$ http服务。

但下面的代码是返回我TrustedValueHolderType对象而不是字符串。

defaultMessage = translate.instant('welcome-message.default.message');

enter image description here

最低配置plunkr https://plnkr.co/edit/ZPtixjNub9kIExiuGIkp?p=preview 打开控制台(清除)。然后点击DE或EN按钮,看到日志

+0

您可以创建一个plunker重现这个工程? – tanmay

+0

@tanmay plunker,请点击DE或EN,打开控制台查看日志:https://plnkr.co/edit/ZPtixjNub9kIExiuGIkp?p=preview – STEEL

+0

不知道怎么回事但是''decodeURIComponent()'修复了这个问题 – STEEL

回答

2

是的,正如评论中提到的,decodeURIComponent可能会解决它。但这里是被摆在首位造成这样的:

$translateProvider.useSanitizeValueStrategy('sce') 

这个编码您的输出$translate全球..这就是为什么你能得到它的工作使用decodeURIComponent

也许你可以使用不同的策略。 angular-translate guide似乎暗示escape策略为此。

这里有一个forked plunkerescape战略,而无需使用decodeURIComponent

相关问题