javascript - Injecting a script tag with ngBindHtml - Stack Overflow

I have external API data which is a user generated content. The client wants to dynamically update his

I have external API data which is a user generated content. The client wants to dynamically update his own site with this feed, including the ability to use JavaScript.

<div ng-bind-html="post.content"></div>

Will display anything that is HTML or CSS but does not work with JavaScript:

"content":"<div>Hello Stack</div><script>alert('whats up?');</script>"

I have tried including ngSanitize as well as using ng-bind-html-unsafe.

No dice.

I have external API data which is a user generated content. The client wants to dynamically update his own site with this feed, including the ability to use JavaScript.

<div ng-bind-html="post.content"></div>

Will display anything that is HTML or CSS but does not work with JavaScript:

"content":"<div>Hello Stack</div><script>alert('whats up?');</script>"

I have tried including ngSanitize as well as using ng-bind-html-unsafe.

No dice.

Share Improve this question edited Mar 4, 2016 at 15:00 isherwood 61.2k16 gold badges121 silver badges169 bronze badges asked Jul 4, 2013 at 2:27 Dan KanzeDan Kanze 18.6k28 gold badges84 silver badges135 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You have to include jQuery for this to work.

After some searching I came across https://stackoverflow./a/14088380/1264846.

Example plunkr: http://plnkr.co/edit/zEXXCB459Tp25VJiyyZb?p=preview

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742420602a4440606.html

相关推荐

  • javascript - Injecting a script tag with ngBindHtml - Stack Overflow

    I have external API data which is a user generated content. The client wants to dynamically update his

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信