我有外部API数据,这是用户生成的内容。客户希望使用此Feed动态更新自己的网站,包括使用JavaScript的功能。
<div ng-bind-html="post.content"></div>
将显示任何HTML或CSS但不适用于JavaScript的内容:
"content":"<div>Hello Stack</div><script>alert('whats up?');</script>"
我尝试过包含ngSanitize
以及使用ng-bind-html-unsafe
。
没有骰子。
答案 0 :(得分:5)
你必须包含jQuery才能工作。
经过一番搜索后,我遇到了https://stackoverflow.com/a/14088380/1264846。
示例plunkr:http://plnkr.co/edit/zEXXCB459Tp25VJiyyZb?p=preview