使用Angular JS ng-repeat的动态背景图片 [英] Dynamic background image with Angular JS ng-repeat

查看:144
本文介绍了使用Angular JS ng-repeat的动态背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Id喜欢使用angular的ng-repeat指令显示动态背景图像.

Id like to display dynamic background images using angular's ng-repeat directive.

目前,我通过将其设置为内联样式来实现此目的,

At the moment Im doing this by setting it as an inline style like so:

<div ng-repeat="thing in things" 
     style="background-image: url({{thing.image}})" >
</div

我宁愿使用标准的角度工具来完成此任务,并避免使用内联样式.我将使用ng-style设置静态背景图像,但是对于不确定数量的对象来说,这似乎不切实际.

I would prefer to use standard angular tools to accomplish this and avoid using inline styles. I would set a static background image using ng-style but this does not seem practical for an indeterminate number of objects.

这种事情的正确解决方案是什么?

What is the correct solution for something like this?

推荐答案

您可以将其用于以下的<img>标记

you can use it into <img> tags like below

<img ng-repeat="x in array" src="{{ x.image_url }}" style="static inline stylesheet" />

或使用

<img ng-repeat="x in array" ng-src="x.image_url" style="static inline stylesheet" />

这篇关于使用Angular JS ng-repeat的动态背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆