I have a simple presentation like this
<div id="{{item.id}}" ng-repeat="item in itemList">
<div ng-bind-html="item.html"></div>
</div>
The item.html contains html like this:
<a href="http://www.youtube.com"><img src="icons/youtube.png" alt="Youtube"/></a>
However, the resulting html does not load the image:
<a href="http://www.youtube.com"><img alt="Youtube"/></a>
After some searching, looks like angularjs does this to avoid cross-site scripting, but i was able to load an image from youtube directly.
<a href="http://www.youtube.com"><img src="http://img.youtube.com/vi/9bZkp7q19f0/0.jpg" alt="Youtube"/></a>
Further more, I was able to load all the images by using ng-bind-html-unsafe.
<div id="{{item.id}}" ng-repeat="item in itemList">
<div ng-bind-html-unsafe="item.html"></div>
</div>
If I use ng-bind-html-unsafe, I don't need the ngSanitize module anymore, meaning my code is less secure? I do have use cases where I load images from external sources.
Coming to my questions:
What is the difference between ng-bind-html and ng-bind-html-unsafe apart from what I have mentioned above. Is there any documentation about this? I could not find any.
How do I accomplish loading images from the host server and external servers, and not having to use the unsafe directive?
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…