[英]Let angularjs not to add slashes before every single and double quotes
I use the following to bind html to a span tag. 我使用以下内容将html绑定到span标签。
<span ng-bind-html="qn.quest_text"></span>
But the content get displayed with slashes before every single and double quotes. 但是,内容在每个单引号和双引号之前都用斜杠显示。
Example : Lorem Ipsum has been the industry\\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 示例:Lorem Ipsum自1500年代以来一直是行业的标准伪文本,当时一位不知名的打印机拿起一个厨房,将其打乱成一本样本书。
How can I prevent angular from adding slashes before every quotes? 如何防止angular在每个引号前添加斜线?
向应用程序添加角度清理。
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular-sanitize.js"></script>
You can use Strict Contextual Escaping ( https://docs.angularjs.org/api/ng/service/ $sce) to escape your Text. 您可以使用严格的上下文转义( https://docs.angularjs.org/api/ng/service/ $ sce)来转义文本。
What you need to do is, include the $sce
service into your controller, define a small function which turns your text into trusted, for example : 您需要做的是,将
$sce
服务包含到您的控制器中,定义一个小的函数,该函数会将您的文本变成可信任的,例如:
$scope.to_trusted = function(string) {
return $sce.trustAsHtml(string);
}
Then you can simply use this in your view, like this, 然后,您可以像这样在您的视图中简单地使用它,
<span ng-bind-html="to_trusted(qn.quest_text)"></span>
You can also try, trustAs(type, value)
method, where you can try different types, eg url, resourceUrl, html, js and css. 您也可以尝试使用
trustAs(type, value)
方法,在其中可以尝试不同的类型,例如url,resourceUrl,html,js和css。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.