[英]AngularJS: ng-class for dynamic base64 encoded image as background-image
Anyone managed to use ng-class for placing dynamic base64 encoded images as background-images for a div yet? 有人设法使用ng-class将动态base64编码的图像作为div的背景图像放置了吗? Seems to work for JQuery (see Is there a way to set background-image as a base64 encoded image in javascript? ) but I haven't figured out any solution for AngularJS yet.
似乎适用于JQuery(请参阅是否可以在javascript中将background-image设置为base64编码的图像? ),但我还没有找到AngularJS的任何解决方案。 This approach of mine does not seem to work out:
我的这种方法似乎无法解决:
<div class="col-xs-2" ng-style="{'background-image':'url(data:image/jpeg;base64,{{dynamicImage}})'}">...</div>
dynamicImage
holds the base64 image string which is loaded on the fly via a REST webservice. dynamicImage
包含base64图像字符串,该字符串通过REST Web服务动态加载。 Any idea if this works at all and how? 知道这是否可行以及如何运作吗?
Don't use {{}}
interpolation inside ng-style
that will throw an $parser
error while evaluating that expression. 不要在
ng-style
内使用{{}}
插值,这会在评估该表达式时引发$parser
错误。 Simply do string
concatenation inside ng-style
. 只需在
ng-style
内进行string
连接。
<div class="col-xs-2"
ng-style="{'background-image':'url(data:image/jpeg;base64,'+dynamicImage+')'}">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.