[英]How to escape single quotes in ng-init
Let's say we are passing data from apache velocity to angularjs and the data is some string that contain quotes, 假设我们正在将数据从Apache速度传递到angularjs,而数据是一些包含引号的字符串,
the error on screen: 屏幕上的错误:
Error: [$parse:lexerr] http://errors.angularjs.org/1.2.22/$parse/lexerr?
p0=Unterminated%20quote&p1=s%20327-
my code : 我的代码:
<span ng-init='draftDemands=$draftDemands;'>
how to solve this problem 如何解决这个问题呢
Are you escaping characters in Velocit's generated code? 您是否在Velocit的生成代码中转义了字符? https://velocity.apache.org/tools/2.0/apidocs/org/apache/velocity/tools/generic/EscapeTool.html https://velocity.apache.org/tools/2.0/apidocs/org/apache/velocity/tools/generic/EscapeTool.html
Check also how angular does escaping via: Strict Contextual Escaping . 还可以通过以下方式检查角度逃逸的方式: 严格的上下文逃逸 。 So there is no need to render characters as HTML explicitly. 因此,无需显式将字符呈现为HTML。
This discussion could put some more light on the case . 这次讨论可以为案件提供更多启示 。
This should also work: how to pass special characters into ng-init in angularjs from python 这也应该起作用: 如何从python将特殊字符传递到angularjs的ng-init中
当我使用$ esc.xml($ draftDemands)时,它在我的最后一个示例中有效,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.