如何通过特殊字符到NG-INIT从蟒蛇angularjs蟒蛇、特殊字符、INIT、NG

2023-09-13 03:25:05 作者:撩妹一把手

我使用的NG-init初始化我的网页上的一些价值观,但我有一些问题,当值包含特殊字符。

I am using ng-init to initialize some values on my page but I am having some issues when the values contain special characters.

现在我用这个语法从蟒蛇的价值观传递给角:

Right now I use this syntax to pass the values from python to angular:

<span ng-init="company_name='{{ account.company_name|escape }}';"></span>

大部分工作,但现在我有一个帐户名时空闲大象的,这会导致一些问题。

most of the time it works, but now I have an account name "idle-elephant's" which causes some issues.

我收到以下错误:

Error: [$parse:lexerr] http://errors.angularjs.org/undefined/$parse/lexerr?p0=Unterminated%20quote&p1=s%2029-31%20%5B'%3B%5D&p2=company_name%3D'idle-elephant's'%3B

如何处理字符串,因此它正确传递字符串?

How do I handle the string, so it passes the string correctly?

谢谢托马斯

推荐答案

您在单引号前添加一个反斜杠逃脱它,所以闲置大象应输出闲置大象\\的

You escape it by adding a backslash before the single quote, so idle-elephant's should be outputted as idle-elephant\'s.