Angular 根据类更改图像 src [英] Angular Change image src depending on class
本文介绍了Angular 根据类更改图像 src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果图像有加载"类,我需要将图像源更改为{{item.preview2}}"
<img src="{{item.preview}}" class="grid-img"/>
解决方案
在您描述的情况下,我将仅使用 ng-if 来控制将哪些元素呈现给 DOM.例如:
<img ng-if="item.loaded" src={{item.preview2}} class="grid-img-loaded"/><img ng-if="!item.loaded" src={{item.preview}} class="grid-img"/>
希望这会有所帮助.
If image has 'loaded' class, i need to change image src to "{{item.preview2}}"
<div ng-repeat="item in items">
<img src="{{item.preview}}" class="grid-img" />
</div>
解决方案
In the case you describe I would just use ng-if to control what elements are rendered to the DOM. for example:
<img ng-if="item.loaded" src={{item.preview2}} class="grid-img-loaded"/>
<img ng-if="!item.loaded" src={{item.preview}} class="grid-img"/>
Hope this helps.
这篇关于Angular 根据类更改图像 src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文