角$ translate.instant回报对象,而不是字符串
问题描述:
进出口使用"angular-translate": "^2.15.1"
与$translateProvider.useSanitizeValueStrategy('sce')
在我的控制,我需要一个翻译字符串值传递给$ http服务。
但下面的代码是返回我TrustedValueHolderType
对象而不是字符串。
defaultMessage = translate.instant('welcome-message.default.message');
最低配置plunkr https://plnkr.co/edit/ZPtixjNub9kIExiuGIkp?p=preview 打开控制台(清除)。然后点击DE或EN按钮,看到日志
答
是的,正如评论中提到的,decodeURIComponent
可能会解决它。但这里是被摆在首位造成这样的:
$translateProvider.useSanitizeValueStrategy('sce')
这个编码您的输出$translate
全球..这就是为什么你能得到它的工作使用decodeURIComponent
。
也许你可以使用不同的策略。 angular-translate
guide似乎暗示escape
策略为此。
这里有一个forked plunker与escape
战略,而无需使用decodeURIComponent
您可以创建一个plunker重现这个工程? – tanmay
@tanmay plunker,请点击DE或EN,打开控制台查看日志:https://plnkr.co/edit/ZPtixjNub9kIExiuGIkp?p=preview – STEEL
不知道怎么回事但是''decodeURIComponent()'修复了这个问题 – STEEL