英文:
string interpreted incorrectly in angularjs
问题
我在golang中有一个字符串,如下所示。
discount = " ("+discount+"% off)"
当通过angularjs传递给html时,显示如下:
(10 %o(MISSING)ff)
有任何想法为什么会这样发生吗?
提前感谢。
英文:
I have a string in golang as follows.
discount = "("+discount+"% off)"
when passed to html via angularjs it is displayed as follows
(10 %o(MISSING)ff)
Any idea why it is happening?
Thanks in advance.
答案1
得分: 2
在你的HTML渲染过程中,有一部分代码将字符串通过go的fmt.Sprintf
或类似的方式进行处理。尝试通过加倍百分号来转义%符号:
discount = " (" + discount + "%% off)"
可以参考http://play.golang.org/p/S_GEJXSfnD 查看一个实时示例。
英文:
Something in your HTML rendering process is passing the string through go's fmt.Sprintf
or similar. Try escaping the % by doubling it:
discount = "("+discount+"%% off)"
See http://play.golang.org/p/S_GEJXSfnD for a live example.
答案2
得分: 0
看起来你需要对字符串进行转义。尝试使用这个模块:http://golang.org/pkg/html/
英文:
Looks like you need to escape the string. Try to use this module: http://golang.org/pkg/html/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论